当前位置:网站首页>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
边栏推荐
猜你喜欢

cmake配置libtorch报错Failed to compute shorthash for libnvrtc.so

Detailed explanation of MATLAB drawing function plot

MATLAB制作简易小动画入门详解

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

4. Publish Posts, Comment on Posts

mysql的索引结构为什么选用B+树?

利用plot_surface命令绘制复杂曲面入门详解

【STM32学习1】基础知识与概念明晰

MATLAB绘图函数fplot详解

Spark及相关生态组件安装配置——快速回忆
随机推荐
极简式 Unity 获取 bilibili 直播弹幕、SC、上舰、礼物等 插件
LeetCode 2354. 优质数对的数目 二进制01表示和集合之间的转换
word方框怎么打勾?
golang之GMP调度模型
pytorch模型转libtorch和onnx格式的通用代码
Open the door of power and electricity "Circuit" (2): Power Calculation and Judgment
What should I do if the Win10 system sets the application identity to automatically prompt for access denied?
Based on the matrix calculation in the linear regression equation of the coefficient estimates
Lightweight AlphaPose
第三十一章:二叉树的概念与性质
开心一下,9/28名场面合集
2.登录退出,登录状态检查,验证码
KiCad Common Shortcuts
Flink + sklearn - use JPMML implement flink deployment on machine learning model
Summarize computer network super comprehensive test questions
mysql的索引结构为什么选用B+树?
Codeforces Round #624 (Div. 3)
第二十五章:一文掌握while循环
5.事务管理
第二十八章:解题技巧