当前位置:网站首页>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
边栏推荐
- Open the door to electricity "Circuit" (3): Talk about different resistance and conductance
- Unity-Post Processing
- 深入理解Mysql索引底层数据结构与算法
- 模板系列-二分
- 专硕与学硕
- 关于混淆的问题
- 模板系列-并查集
- LeetCode 2353. 设计食物评分系统 维护哈希表+set
- 面试汇总
- Compilation error D8021: Invalid numeric argument '/Wextra' cl command line error d8021 invalid numeric argument '/Wextra'
猜你喜欢
随机推荐
利用plot_surface命令绘制复杂曲面入门详解
mysql的索引结构为什么选用B+树?
TypeScript
3. User upload avatar
推开机电的大门《电路》(二):功率计算与判断
STM32LL库使用——SPI通信
Detailed introduction to the hierarchical method of binary tree creation
队列与栈
剑指offer:合并两个排序的链表
7. Redis
总结计算机网络超全面试题
Introduction to in-order traversal (non-recursive, recursive) after binary tree traversal
2021-06-06
二叉树创建之层次法入门详解
Article pygame drag the implementation of the method
5.事务管理
计算机导论——数据库
pygame拖动条的实现方法
编译error D8021 :无效的数值参数“/Wextra” cl command line error d8021 invalid numeric argument ‘/wextra‘
Based on the matrix calculation in the linear regression equation of the coefficient estimates