当前位置:网站首页>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
边栏推荐
猜你喜欢
MATLAB绘图函数ezplot入门详解
2.登录退出,登录状态检查,验证码
unity-shader(入门)
Codeforces Round #605 (Div. 3)
How to update Win11 sound card driver?Win11 sound card driver update method
STM32LL library - USART interrupt to receive variable length information
奇技淫巧-位运算
第二十五章:一文掌握while循环
十天学习Unity3D脚本(一)九个回调
Win11 keeps popping up User Account Control how to fix it
随机推荐
深入理解Mysql索引底层数据结构与算法
推开机电的大门《电路》(二):功率计算与判断
Open the door of electricity "Circuit" (1): voltage, current, reference direction
Based on the least squares linear regression equation coefficient estimation
Installation and configuration of Spark and related ecological components - quick recall
cmake configure libtorch error Failed to compute shorthash for libnvrtc.so
倍增和稀疏表
Mysql的锁
Win11 keeps popping up User Account Control how to fix it
Yolov5 official code reading - prior to transmission
Unity-Ads广告插件
深入理解Golang之Map
casbin模型
7. Redis
Detailed introduction to the hierarchical method of binary tree creation
Open the door to electricity "Circuit" (3): Talk about different resistance and conductance
unity-shader(中级)
使用libcurl将Opencv Mat的图像上传到文件服务器,基于post请求和ftp协议两种方法
利用plot_surface命令绘制复杂曲面入门详解
剑指offer:数值的整数次方