Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Object.DontDestroyOnLoad 加载时不销毁
# [Object](Object.html "Go to Object scripting documentation").DontDestroyOnLoad 加载时不销毁 static function *DontDestroyOnLoad* (*target* : Object) : void *Description* 描述 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. 当加载一个新关卡时,所有场景中所有的物体被销毁,然后新关卡中的物体被加载进来。为了保持在加载新关卡时物体不被销毁,使用 DontDestroyOnLoad 保持,如果物体是一个组件或游戏物体,它的整个 transform 层次将不会被销毁,全部保留下来。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Awake() { DontDestroyOnLoad(transform.gameObject); } } ``` ``` // Make this game object and all its transform children // survive when loading a new scene. //当加载新场景的时候,使游戏物体和它所有的transform子物体存活下来 function Awake () { DontDestroyOnLoad (transform.gameObject); } ```
da
2022年5月23日 14:11
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码