DontDestroyOnLoad
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_DontDestroyOnLoad.html
public static void DontDestroyOnLoad(Objecttarget);
Parameters
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层次将不会被销毁,全部保留下来。
// Make this game object and all its transform children
// survive when loading a new scene.
//当加载新场景的时候,使游戏物体和它所有的transform子物体存活下来
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
using UnityEngine;
using System.Collections;
using UnityEngine;
using System.Collections; public class DontDestroyOnLOAD : MonoBehaviour {
private Transform m_root = null; void Start() {
Debug.LogError("Start");
try {
int i = ;
int[] tempInt = new int[];
int j = tempInt[];
}
catch (System.Exception ex) {
Debug.LogException(ex);
}
Debug.LogError("Start End");
} void Awake() {
Debug.LogError("Awake");
string rootName = string.Format("{0}s", "DontDestroyOnLOAD");
GameObject gameObj = new GameObject(rootName);
GameObject.DontDestroyOnLoad(gameObj);
m_root = gameObj.transform;
Debug.LogError("Awake End");
} void OnDisable() {
Debug.LogError("OnDisable");
Debug.LogError("OnDisable End");
} void OnEnable() {
Debug.LogError("OnEnable");
Debug.LogError("OnEnable End");
}
}
第一种情况,start会默认执行;
最开始:脚本的勾勾,勾上,那么就会执行Awake、onEnbale、Start
去掉勾勾,执行onDisable 再加上勾勾执行OnEnable
第二种情况,start是没有执行的,只有在OnEnable时,才会在执行Start,且只执行一次
DontDestroyOnLoad的更多相关文章
- Unity3D Object.DontDestroyOnLoad 备忘
初学Untiy3D,记录备忘. public static void DontDestroyOnLoad(Object target); Makes the object target not be ...
- DontDestroyOnLoad(Unity3D开发之五)
Unity中我们从A场景切换到B场景的时候,A场景全部对象都会销毁,但有时候我不须要销毁某些东西. 比方一个简单的游戏的背景音乐,我不须要多次反复创建,多个场景播放这一个即可了.这个时候就须要用到Do ...
- u3d DontDestroyOnLoad多场景问题
using UnityEngine; using System.Collections; public class DontDel : MonoBehaviour { public GameObjec ...
- unity3d中的DontDestroyOnLoad来回切换出现多个实例问题
在用Unity3D开发游戏中,我们会经常创建多个场景,但是在场景过度的时候,通常场景中的对象会被删除.所以Unity3D给了我们一个不删除前一个 场景中的某一个对象或者脚本的API,那就是“DontD ...
- Application.LoadLevel & Object.DontDestroyOnLoad
[Application.LoadLevel] 只有在File->Build Setting中设置了的按钮才能被加载. 当level加载完成后,MonoBehaviour.OnLevelWasL ...
- Unity3D研究院之DontDestroyOnLoad的坑
http://www.xuanyusong.com/archives/2938 Unity中的一个方法DontDestroyOnLoad可以让某些游戏对象在切换场景的时候不是施放,听起来是一个非常好的 ...
- unity, 慎用DontDestroyOnLoad
如果想让一个节点切换场景时不销毁,可以为它添加如下脚本: using UnityEngine;using System.Collections; public class dontDestroyOnL ...
- 【转】DontDestroyOnLoad(Unity3D开发之五)
原文 http://blog.csdn.net/cocos2der/article/details/38320773 主题 Unity3D Unity中我们从A场景切换到B场景的时候,A场景所有对象 ...
- 【转】Unity3D研究院之DontDestroyOnLoad的坑
http://www.xuanyusong.com/archives/2938 Unity中的一个方法DontDestroyOnLoad可以让某些游戏对象在切换场景的时候不是施放,听起来是一个非常好的 ...
随机推荐
- 用Java实现非阻塞通信
用ServerSocket和Socket来编写服务器程序和客户程序,是Java网络编程的最基本的方式.这些服务器程序或客户程序在运行过程中常常会阻塞.例如当一个线程执行ServerSocket的acc ...
- 【HDOJ】2896 病毒侵袭
AC自动机模板题. #include <iostream> #include <cstdio> #include <cstring> #include <qu ...
- bzoj3192
把堆顶和堆顶接起来,然后用树状数组模拟即可不得不说一开始我竟然把100000*100000当成不超出longint 而忘开int64,无药可救…… ..] of longint; now,n1,n2, ...
- WordPress /wp-admin/users.php畸形s参数路径泄漏漏洞
漏洞版本: WordPress 2.7.x WordPress 2.8.x WordPress 2.9.x WordPress 3.0.x WordPress 3.1.x WordPress 3.2. ...
- 【转】文件读写NDK(或Linux)
原文网址:http://www.ithao123.cn/content-10709539.html 使用NDK进行文件读写,有利于保存数据的安全性,项目需要,要文件读写从Java中处理搬到Linux平 ...
- 【动态规划】Vijos P1121 马拦过河卒
题目链接: https://vijos.org/p/1616 题目大意: 卒从(0,0)走到(n,m),只能向下或向右,不能被马一步碰到或走到马,有几种走法. 题目思路: [动态规划] 把马控制的地方 ...
- IIS6.0服务器搭建网站无法访问解决方法
IIS6.0服务器搭建网站无法访问解决方法 IIS6.0服务器搭建网站无法访问解决方法很多朋友在用IIS6架网站的时候遇到不少问题,而这些问题有些在过去的IIS5里面就遇到过,有些是新出来的, ...
- hdu 4705 dfs统计更新节点信息
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705 #pragma comment(linker, "/STACK:16777216&qu ...
- AGG 之贝塞尔插值
原文: http://liyiwen.iteye.com/blog/705489 之前 comp.graphic.algorithms 上有一个讨论,是关于怎么样使用曲线对多边形进行插值处理,使得最终 ...
- ActionScript 3.0数组操作
var arr:Array=new Array();arr=["a","b","c"]; //赋初值,注意这里的即使单个字符赋值使用的是& ...



