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

Unity Destory的更多相关文章

  1. Unity内存理解(转)

    Unity3D 里有两种动态加载机制:一个是Resources.Load,另外一个通过AssetBundle,其实两者区别不大. Resources.Load就是从一个缺省打进程序包里的AssetBu ...

  2. [转]全面理解Unity加载和内存管理

    [转]全面理解Unity加载和内存管理 最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Resources.Load,一是通过AssetBundle,其实两者本质 ...

  3. 【转载】Unity 优雅地管理资源,减少占用内存,优化游戏

    转自:星辰的<Unity3D占用内存太大的解决方法> 最近网友通过网站搜索Unity3D在手机及其他平台下占用内存太大. 这里写下关于Unity3D对于内存的管理与优化. Unity3D  ...

  4. 【转载】Unity 合理安排增量更新(热更新)

    原帖地址:由于我看到的那个网站发的这篇帖子很大可能是盗贴的,我就暂时不贴地址了.避免伤害原作者 原版写的有点乱,我个人修改整理了下. --------------------------------- ...

  5. Unity内存申请和释放

    转自:http://www.jianshu.com/p/b37ee8cea04c 1.资源类型 GameObject, Transform, Mesh, Texture, Material, Shad ...

  6. Unity 全面理解加载和内存管理

    最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Resources.Load,一是通过AssetBundle,其实两者本质上我理解没有什么区别.Resources ...

  7. Unity 3D 粒子系统的一点经验

    http://hunterwang.diandian.com/post/2012-10-21/40041523890 最近做东西需要增加效果,简单的运用了一下粒子效果,真心感觉比较难调整好效果.同时也 ...

  8. Unity 3D中的内存管理

    本文欢迎转载,但烦请保留此行出处信息:http://www.onevcat.com/2012/11/memory-in-unity3d/ Unity3D在内存占用上一直被人诟病,特别是对于面向移动设备 ...

  9. Unity动态加载和内存管理(三合一)

    原址:http://game.ceeger.com/forum/read.php?tid=4394#info 最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Re ...

随机推荐

  1. VMware Workstation 12 Pro 之安装林耐斯优麒麟 X64-UI系统

    VMware Workstation 12 Pro 之安装林耐斯优麒麟 X64-UI系统... ------------------------------- -------------------- ...

  2. php Yii2使用registerJs或registerCss报错syntax error, unexpected end of file

    解决方法: 注册时$js=<<<JS .....JS;//结尾处JS;应单独成行并且没有空格  JS;//这样就会报错,多了空格JS;//这样就不会

  3. java web开发时的绝对路径与相对路径

    相对路径 不以/开头的路径为相对路径,使用相对路径时的路径为当前访问的文件的父目录,即如果现在访问文件的路径为http://localhost:8080/项目名/目录/文件,那么使用相对路径时路径前缀 ...

  4. javascript常用函数实现的收集

    收集了一些比较常用的javascript函数. 1.字符串长度截取 function cutstr(str, len) { var temp, icount = 0, patrn = /[^\x00- ...

  5. JS组件系列——再推荐一款好用的bootstrap-select组件,亲测还不错

    前言:之前分享过两篇bootstrap下拉框的组件:JS组件系列——两种bootstrap multiselect组件大比拼  和 JS组件系列——Bootstrap Select2组件使用小结 ,收 ...

  6. CODE大全给你推荐几个免费的leapftp 注册码

    leapftp 2.7.6 注册码, Name: Kmos/CiA in 1999 s/n: MOD1-MO2D-M3OD-NOPQ LeapFTP2.7.5 注册名:swzn 注册码:214065- ...

  7. SQL Server 的锁定和阻塞

    本帖提供两种做法,可避免在 SQL Server 事务锁定时产生的不正常或长时间阻塞,让用户和程序也无限期等待,甚至引起 connection pooling 连接数超过容量. 所谓的「阻塞」,是指当 ...

  8. 转:【Java并发编程】之十九:并发新特性—Executor框架与线程池(含代码)

      Executor框架简介 在Java5之后,并发编程引入了一堆新的启动.调度和管理线程的API.Executor框架便是Java 5中引入的,其内部使用了线程池机制,它在java.util.coc ...

  9. Banner图二三事

      前  言 JRedu 作为一个准前端学员,banner图可是很重要的呢.本人,小白一只,给大家分享几个刚刚学习的基础banner图事件.~~~ 1. 小广告图滚动播放 1.1HTML代码 首先,创 ...

  10. 团队作业8——Beta 阶段冲刺5th day

    一.当天站立式会议 二.每个人的工作 (1)昨天已完成的工作(具体在表格中) 支付功能测试 (2)今天计划完成的工作(具体如下) 完善订单功能 (3)工作中遇到的困难(在表格中) 成员 昨天已完成的工 ...