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 ...
随机推荐
- VMware Workstation 12 Pro 之安装林耐斯优麒麟 X64-UI系统
VMware Workstation 12 Pro 之安装林耐斯优麒麟 X64-UI系统... ------------------------------- -------------------- ...
- mySQl数据库的学习笔记
mySQl数据库的学习笔记... ------------------ Dos命令--先在记事本中写.然后再粘贴到Dos中去 -------------------------------- mySQ ...
- 关于read的例子和条件测试
1.关于read比较两个的大小 #!/bin/sh read -t -p "please input two num:" a b if [ $a -gt $b ]; then ec ...
- DRAM(MT48LC8M32B2)学习
Micron公司,型号为MT48LC8M32B2的DRAM,其86PIN的 TSOP封装引脚定义 Micron公司,型号为MT48LC8M32B2的DRAM,其86PIN的 TSOP封装引脚定义如上图 ...
- SQL查询每个部门工资前三名的员工信息
--通用sql select deptno, ename, sal from emp e1 where ( ) from emp e2 where e2.deptno=e1.deptno and e2 ...
- 如何利用Jmeter做代理录制脚本
如果对于这个Jmeter不太会使用的童鞋,可以去参考其他的教学文档,本文只提供Jmeter的代理使用. 第一步:添加线程组
- postman接口测试工具完整教程
第一部分:基础篇 postman:4.5.11.安装postman进入postman官网,如果是mac系统可以直接点击mac app安装 如果是windows的话,需要在windows下安装chrom ...
- mysql语句的一个问题
刚才在群里有个同学提出了这么一个问题 在Mybatis的mapper文件中有一条语句这么写 说是系统不报错,也没返回,我一看句子应该没什么问题.执行的时候应该是PreparedStatement 执行 ...
- [2014-11-02]为EF6+Mysql+CodeFirst启用Migration
刚为一个EF6 CodeFirst项目启用了Migration,记几个注意点. 启用方法 在Nuget控制台使用以下命令启用Migration Enable-Migrations #此时生成当前数据库 ...
- if __name__ == '__main__' 到底是何方神圣(转)
想必很多初次接触python都会见到这样一个语句,if __name__ == "__main__": 那么这个语句到底是做什么用的呢?在解释之前,首先要声明的是,不管你是多么小白 ...