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);
Unity Destory的更多相关文章
- Unity内存理解(转)
Unity3D 里有两种动态加载机制:一个是Resources.Load,另外一个通过AssetBundle,其实两者区别不大. Resources.Load就是从一个缺省打进程序包里的AssetBu ...
- [转]全面理解Unity加载和内存管理
[转]全面理解Unity加载和内存管理 最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Resources.Load,一是通过AssetBundle,其实两者本质 ...
- 【转载】Unity 优雅地管理资源,减少占用内存,优化游戏
转自:星辰的<Unity3D占用内存太大的解决方法> 最近网友通过网站搜索Unity3D在手机及其他平台下占用内存太大. 这里写下关于Unity3D对于内存的管理与优化. Unity3D ...
- 【转载】Unity 合理安排增量更新(热更新)
原帖地址:由于我看到的那个网站发的这篇帖子很大可能是盗贴的,我就暂时不贴地址了.避免伤害原作者 原版写的有点乱,我个人修改整理了下. --------------------------------- ...
- Unity内存申请和释放
转自:http://www.jianshu.com/p/b37ee8cea04c 1.资源类型 GameObject, Transform, Mesh, Texture, Material, Shad ...
- Unity 全面理解加载和内存管理
最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Resources.Load,一是通过AssetBundle,其实两者本质上我理解没有什么区别.Resources ...
- Unity 3D 粒子系统的一点经验
http://hunterwang.diandian.com/post/2012-10-21/40041523890 最近做东西需要增加效果,简单的运用了一下粒子效果,真心感觉比较难调整好效果.同时也 ...
- Unity 3D中的内存管理
本文欢迎转载,但烦请保留此行出处信息:http://www.onevcat.com/2012/11/memory-in-unity3d/ Unity3D在内存占用上一直被人诟病,特别是对于面向移动设备 ...
- Unity动态加载和内存管理(三合一)
原址:http://game.ceeger.com/forum/read.php?tid=4394#info 最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Re ...
随机推荐
- c语言 内存管理
动态内存是由程序员手动分配,不再使用时,一定记得释放内存. 静态内存是程序开始运行时由编译器分配的内存,它的分配是程序开始编译时完成的,不占用cpu资源.程序中的各种变量在编译源程序时就已经分配了内存 ...
- MySQL、PHP入门
登录MySQL mysql -hlocalhost-uroot -proot 退出MySQL exit 每条语句后必须加分号:----------------------------- ...
- 介绍maven构建的生命周期
介绍maven构建的生命周期 这篇是 https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html 的 ...
- 转每天一个linux命令(8):cp 命令
cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是如果是 ...
- [2016-07-15]结合命令行工具awk和多行文本编辑器快速生成DataSeed代码
目标:根据业务提供的两份数据,生成DataSeed代码 SampleDataA 上海 华东一线 上饶 华东四线 中山 华南二线 临汾 华北四线 临沂 华东二线 SampleDataB 上海 1D04E ...
- [2013-07-22]varnish-cache 安装配置及体验笔记
varnish安装 ubuntu12安装参考 其他系统参考 如果选择了直接从源安装的方式的话,就不要自己去编译了,以免出现意外(悲剧的我,varnishlog 有点问题,之前先编译安装了,再从源安装, ...
- quartz.net使用(通过配置文件进行配置)
在项目Nuget包管理器中搜索:quartz,安装完成之后再项目中引用即可 先定义一个Job,需要实现IJob接口: public class TestJob : IJob { public void ...
- 【BUG】插入或者更新超过限制后写入数据库失败
Error Code: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your ...
- django富文本编辑器
-------------------tinymce富文本编辑器1.下载安装 1.在网站pypi网站搜索并下载"django-tinymce-2.4.0" 2.解压:tar zxv ...
- 10分钟学会ES7+ES8
撰文为何 身为一个前端开发者,ECMAScript(以下简称ES)早已广泛应用在我们的工作当中.了解ECMA机构流程的人应该知道,标准委员会会在每年的6月份正式发布一次规范的修订,而这次的发布也将作为 ...