当前位置:网站首页>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
边栏推荐
- Compilation error D8021: Invalid numeric argument '/Wextra' cl command line error d8021 invalid numeric argument '/Wextra'
- Unity-PlayMaker
- 深入理解Mysql索引底层数据结构与算法
- 利用plot_surface命令绘制复杂曲面入门详解
- Redis常见面试题
- Detailed introduction to the hierarchical method of binary tree creation
- How to solve Win11 without local users and groups
- IPV4和IPV6是什么?
- 使用libcurl将Opencv Mat的图像上传到文件服务器,基于post请求和ftp协议两种方法
- Exotic curiosity-a solution looking - bit operations
猜你喜欢
随机推荐
Yolov5 official code reading - prior to transmission
Introduction to MATLAB drawing functions ezplot explanation
cmake配置libtorch报错Failed to compute shorthash for libnvrtc.so
couldn't find 'libflutter.so' --flutter
pygame拖动条的实现方法
General code for pytorch model to libtorch and onnx format
Redis常见面试题
1.开发社区首页,注册
基于矩阵计算的线性回归分析方程中系数的估计
[System Design and Implementation] Flink-based distracted driving prediction and data analysis system
C语言函数参数传递模式入门详解
TypeScript
2. Log out, log in state examination, verification code
Doubled and sparse tables
pygame图像连续旋转
Unity-Ads广告插件
Win10 computer can't read U disk?Don't recognize U disk how to solve?
4.发布帖子,评论帖子
LeetCode 2353. 设计食物评分系统 维护哈希表+set
Codeforces Round #605 (Div. 3)









