LoginSignup
7
2

More than 5 years have passed since last update.

unity > 物体がある範囲外に移動した時に消えるようにする > Destroy(gameObject);

Last updated at Posted at 2015-08-08
動作確認
Unity 5.1.1-f on MacOS X 10.8.5

消したい物体に以下のスクリプトを関連づけると、その物体が原点から10以上の距離に行った時に消えるようになる。

SphereControl.cs
using UnityEngine;
using System.Collections;

public class SphereControl : MonoBehaviour {

    void Update () {
        float dist = Vector3.Distance (new Vector3 (0, 0, 0), transform.position);
        if (dist > 10.0f) {
            Destroy(gameObject);
        }
    }
}

追記

(2018/01/22)

時間で消す方法は下記で紹介されています。

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2