Unity3D Object.DontDestroyOnLoad 备忘

初学Untiy3D,记录备忘。

public static void DontDestroyOnLoad(Object target);

Makes the object target not be destroyed automatically when loading a new scene.

When loading a new level all objects in the scene are destroyed, then the objects in the new level are loaded. In order to preserve an object during level loading call DontDestroyOnLoad on it. If the object is a component or game object then its entire transform hierarchy will not be destroyed either.

 

按Untiy 5.4.0b7 文档上的解释,public static void DontDestroyOnLoad(Object target) 中的参数target以及其层级结构下的GameObject及MonoBehavior都不会在场景切换过程中被销毁。

应用场景:

1. 游戏基本管理器Component要Add到target下。

2. 与游戏全局数据和状态相关的控制逻辑Component要Add到target下。

注意事项:

1. 与当前场景相关的数据不要放在target下,或者这些数据要在切换场景时清空,即卸载掉相关资源

转载于:https://www.cnblogs.com/moneymanymany/p/5228947.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值