using UnityEngine;
using System.Collections;
public class destroy : MonoBehaviour {
void Start () {
print("start");
destroyObject();
//destroyImmediateObj();
print(gameObject.name);
/*
destroyObject销毁gameObject后还能正常显示名字,DestroyImmediate销毁后则不能。
因为:
DestroyImmediate立即对对像进行销毁;
Destroy销毁场景中的物体,但内存中还存在,当令它需要销毁时,只是给一个标识。
而内存中它依然是存在的,只有当内存不够,或一段时间没有再次被引用时
或者更多合理的条件满足),机制才会将它销毁并释放内存。
*/
}
void Update () {
print("update");
}
private void destroyObject()
{
//销毁对象本身
Destroy(gameObject, 1);
//销毁其他对象
Destroy(GameObject.Find("Plane"));
//销毁组件
Destroy(GetComponent<Rigidbody>());
}
private void destroyImmediateObj()
{
DestroyImmediate(gameObject);
}
}