当前位置:网站首页>unity Domain Reload & scene Reload 静态变量重置
unity Domain Reload & scene Reload 静态变量重置
2022-08-02 14:12:00 【FatherOfCodingMan】
关闭 Domain Reload 选项后,c#的静态变量在下次运行时不会怎么重置,需要手动添加重置代码。使用下面的属性设置重置变量函数。
using UnityEngine;
public class StaticCounterExampleFixed : MonoBehaviour
{
static int counter = 0;
//此属性
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Init()
{
Debug.Log("Counter reset.");
counter = 0;
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Jump"))
{
counter++;
Debug.Log("Counter: " + counter);
}
}
}Asset Import Order
If you are scripting using the AssetDatabase class, it’s important to understand how the order of Unity’s import processes can affect your scripts, otherwise you may get unexpected results. The order is as follows:
- Import Script Assets (.cs, .dll, .asmdef files)
- Compilation
- Domain reload
- InitializeOnLoad callback
- Import all other assets
Unity - Manual: Details of disabling Domain and Scene Reload
边栏推荐
猜你喜欢

6.统一记录日志

MATLAB图形加标注的基本方法入门简介

Mysql的锁

Doubled and sparse tables

cmake configure libtorch error Failed to compute shorthash for libnvrtc.so

How to solve Win11 without local users and groups

Network Security Packet Capture

Summarize computer network super comprehensive test questions

二叉树遍历之后序遍历(非递归、递归)入门详解

深入理解Golang之Map
随机推荐
永久更改pip源
Article pygame drag the implementation of the method
pygame draw arc
面试汇总
pygame图像连续旋转
二叉树遍历之后序遍历(非递归、递归)入门详解
剑指offer:数值的整数次方
5. Transaction management
STM32LL库使用——SPI通信
二叉树创建之层次法入门详解
1. Development community homepage, register
2.登录退出,登录状态检查,验证码
Software Testing Basics (Back)
远程连接Ubuntu中的Mysql
In-depth understanding of Golang's Map
2021-06-06
MATLAB绘制平面填充图入门详解
Unity-Ads广告插件
Use tencent cloud builds a personal blog
Detailed introduction to the hierarchical method of binary tree creation