Unity Destory
Object.Destroy
Parameters
obj | The object to destroy. |
t | The optional amount of time to delay before destroying the object. |
Description
Removes a gameobject, component or asset.
The object obj
will be destroyed now or if a time is specified t
seconds from now. If obj
is a Component it will remove the component from the GameObject and destroy it. If obj
is a GameObject it will destroy the GameObject, all its components and all transform children of the GameObject. Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering.
// Kills the game object
Destroy (gameObject); // Removes this script instance from the game object
Destroy (this); // Removes the rigidbody from the game object
Destroy (rigidbody); // Kills the game object in 5 seconds after loading the object
Destroy (gameObject, 5); // When the user presses Ctrl, it will remove the script
// named FooScript from the game object
function Update () {
if (Input.GetButton ("Fire1") && GetComponent (FooScript))
Destroy (GetComponent (FooScript));
}
// Kills the game object
Destroy(gameObject); // Removes this script instance from the game object
Destroy(this); // Removes the rigidbody from the game object
Destroy(rigidbody); // Kills the game object in 5 seconds after loading the object
Destroy(gameObject, 5); // When the user presses Ctrl, it will remove the script
// named FooScript from the game object
void Update()
{
if (Input.GetButton("Fire1") && GetComponent<FooScript>())
{
Destroy(GetComponent<FooScript>());
}
}
Destroy is inherited from the UnityEngine.Object base class. Javascript users should consider making a call to UnityEngine.Object.Destroy, rather than Object.Destroy to avoid references being resolved to the .Net System.Object class.
Note : Destory 继承于UnityEngine 所以如果Destory出现下图情况
可以考虑使用 UnityEngine.Object.Destroy (gameObject);
最新文章
- Angularjs,WebAPI 搭建一个简易权限管理系统 —— WebAPI项目主体结构(四)
- make menuconfig 是一个目录。停止 错误解决
- C#如何设置Listview的行高-高度
- iOS第三方推送-极光推送
- effective c++:尽量替换define,确保对象使用前初始化
- centos 6.5 x64编译有python的vim7.4
- (转载)在mysql中,column &#39;id&#39; in field list is ambiguous
- 笔记︱金融风险控制基础常识——巴塞尔协议+信用评分卡Fico信用分
- mac下Android开发环境的配置
- ajax原生实现
- C#时间格式化显示AM/PM
- Undertow的InMemorySessionManager
- 3D模型文字动画
- selector的例子
- QT注意事项(持续更新...)
- 文件寄生——寻找宿主的不归路(NTFS文件流实际应用)
- Median(vector+二分)
- Mybatis输入输出映射
- 如何修改静态IP地址和动态IP地址
- UUID的定义以及作用