Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Object.Destroy

マニュアルに切り替える
public static void Destroy(Object obj, float t = 0.0F);
public static void Destroy(Object obj, float t = 0.0F);

パラメーター

obj 破壊するオブジェクト
t オブジェクトを破壊するまでのディレイ時間

説明

ゲームオブジェクトやコンポーネント、アセットを削除します

t 秒後にオブジェクトの obj を破壊します。 objComponent の場合、GameObjectからコンポーネントを削除し、破壊します。 objGameObject の場合、GameObject ならびにすべてのコンポーネント、GameObject の子であるすべてのオブジェクトを破壊します。 オブジェクトの破壊は、現在のフレームのアップデート(Update)処理後に行われますが、常にレンダリング前に実行されます。

          

// 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>()); } }

UnityEngine.Object 基本クラスの派生オブジェクトを破壊します。Javascript を使用しているユーザーは、.Net の System.Object クラスとの衝突を回避するために Object.Destroy よりも UnityEngine.Object.Destroy を使用することをおすすめします。