当前位置:网站首页>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
边栏推荐
- 学习笔记(01):activiti6.0从入门到精通-工作流的介绍以及插件的安装
- Installation and configuration of Spark and related ecological components - quick recall
- LeetCode 2343. 裁剪数字后查询第 K 小的数字 暴力+语法考察
- 第三十三章:图的基本概念与性质
- 6.统一记录日志
- 推开机电的大门《电路》(二):功率计算与判断
- 3. User upload avatar
- 1. Development community homepage, register
- unity-shader(入门)
- 计算机导论——数据库
猜你喜欢

Detailed introduction to drawing complex surfaces using the plot_surface command

What should I do if the Win10 system sets the application identity to automatically prompt for access denied?

STM32LL library use - SPI communication

二叉树的遍历:递归法/ 迭代法/ 统一迭代法(强QAQ)

Based on the least squares linear regression equation coefficient estimation

1.开发社区首页,注册

Unity-3D数学

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

Use tencent cloud builds a personal blog

MATLAB绘图命令fimplicit绘制隐函数图形入门详解
随机推荐
极简式 Unity 获取 bilibili 直播弹幕、SC、上舰、礼物等 插件
2021-06-06
4. Publish Posts, Comment on Posts
2.登录退出,登录状态检查,验证码
【STM32学习1】基础知识与概念明晰
How to simulate 1/3 probability with coins, and arbitrary probability?
Manifest merger failed : Attribute [email protected] value=
基于矩阵计算的线性回归分析方程中系数的估计
Summarize computer network super comprehensive test questions
Introduction to MATLAB drawing functions ezplot explanation
IPV4和IPV6是什么?
Codeforces Round #624 (Div. 3)
Use tencent cloud builds a personal blog
第三十一章:二叉树的概念与性质
IDEA 单元测试报错:Class not found
Open the door of electricity "Circuit" (1): voltage, current, reference direction
Happy, 9/28 scene collection
队列与栈
MATLAB图形加标注的基本方法入门简介
推开机电的大门《电路》(二):功率计算与判断