Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Object.Destroy 销毁
# [Object](Object.html "Go to Object scripting documentation").Destroy 销毁 static function *Destroy* (*obj* : Object, *t* : float = 0.0F) : void *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](../Component/Component.html) it will remove the component from the [GameObject](../GameObject/GameObject.html) and destroy it. If obj is a [GameObject](../GameObject/GameObject.html) it will destroy the [GameObject](../GameObject/GameObject.html), all its components and all transform children of the [GameObject](../GameObject/GameObject.html). Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering. 物体 obj 现在被销毁或在指定了 t 时间过后销毁。如果 obj 是组件,它将从 [GameObject](../GameObject/GameObject.html) 销毁组件 component。如果 obj 是 [GameObject](../GameObject/GameObject.html) 它将销毁 [GameObject](../GameObject/GameObject.html) 全部它的组件和 GameObject 全部 transform 子物体。实际物体的销毁总是延迟到当前更新循环后,但总是渲染之前完成。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { if (Input.GetButton("Fire1") && GetComponent ``` ``` // 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 //加载物体5秒后销毁游戏物体 Destroy (gameObject, 5); // When the user presses Ctrl, it will remove the script // named FooScript from the game object //当按下Ctrl将从游戏物体删除名为FooScript的脚本 function Update () { if (Input.GetButton ("Fire1") && GetComponent (FooScript)) Destroy (GetComponent (FooScript)); } ```
da
2022年5月23日 14:11
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码