Object.Destroy

 
 
public static function Destroy(obj: Object, t: float = 0.0F): void;
public static void Destroy(Object obj, float t = 0.0F);

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);

最新文章

  1. Angularjs,WebAPI 搭建一个简易权限管理系统 —— WebAPI项目主体结构(四)
  2. make menuconfig 是一个目录。停止 错误解决
  3. C#如何设置Listview的行高-高度
  4. iOS第三方推送-极光推送
  5. effective c++:尽量替换define,确保对象使用前初始化
  6. centos 6.5 x64编译有python的vim7.4
  7. (转载)在mysql中,column &#39;id&#39; in field list is ambiguous
  8. 笔记︱金融风险控制基础常识——巴塞尔协议+信用评分卡Fico信用分
  9. mac下Android开发环境的配置
  10. ajax原生实现
  11. C#时间格式化显示AM/PM
  12. Undertow的InMemorySessionManager
  13. 3D模型文字动画
  14. selector的例子
  15. QT注意事项(持续更新...)
  16. 文件寄生——寻找宿主的不归路(NTFS文件流实际应用)
  17. Median(vector+二分)
  18. Mybatis输入输出映射
  19. 如何修改静态IP地址和动态IP地址
  20. UUID的定义以及作用

热门文章

  1. RedHat 7 常用命令总结
  2. DHCP解析
  3. 新博客在SEO方面需要注意哪几点?
  4. poj 3013 Big Christmas Tree
  5. 修改Tomcat服务器默认端口
  6. 排序算法——选择排序(js语言实现)
  7. 写给后端的前端笔记:定位(position)
  8. Mysql 掌握要点
  9. oracle字段由中文前缀加数字,数字自动增长的实现
  10. Spark Mllib框架1