Object.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 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.
物体obj现在被销毁或在指定了t时间过后销毁。如果obj是组件,它将从GameObject销毁组件component。如果obj是GameObject它将销毁GameObject全部它的组件和GameObject全部transform子物体。实际物体的销毁总是延迟到当前更新循环后,但总是渲染之前完成。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Update() {
if (Input.GetButton("Fire1") && GetComponent())
Destroy(GetComponent());
}
public void Awake() {
Destroy(gameObject);
Destroy();
Destroy(rigidbody);
Destroy(gameObject, 5);
}
}
// 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));
}
最后修改:2010年12月8日 Wednesday 23:23