原文链接:https://blog.csdn.net/NCZ9_/article/details/84203714
参考链接:https://blog.csdn.net/lee514/article/details/80995048
方法一:GameObject.Destroy(游戏物体(gameObject类型));
GameObject.Destroy(gameObject,2.0f);
Destory是静态方法,用类名加点的形式调用
方法中有两个参数
gameObject表示要销毁的游戏对象自身
2.0f表示2秒后销毁,可以任意指定时间
也可以用随机数函数生成随机的销毁时间,例如:Random.Range(1.0f,5.0f),表示1到5秒之间的秒数销毁游戏对象。
方法二:GameObject.DestroyImmediate(游戏物体(gameObject类型));
方法三:GameObject.DestroyObject(游戏物体(gameObject类型));
方法在脚本继承MonoBehaviour时可直接使用,无需通过GameObject调用。
销毁物体:Destroy、DestroyImmediate、DestroyObject
原文:https://www.cnblogs.com/yifengs/p/14829977.html