LoginSignup
13
10

More than 5 years have passed since last update.

オブジェクトが画面外に出たら削除したい

Last updated at Posted at 2015-06-04

オブジェクトは初期状態で画面内に存在しており、それが画面から外れたときに自動的に削除するという処理を実装したい。例えばシューティングゲームの弾など。

これはRenderer.isVisibleで判定すれば簡単に実装できる。

MyComponent.cs
void Update() {

  if (!GetComponent<Renderer>().isVisible) {
    Destroy(this.gameObject);
  }

}

オブジェクトが画面外で生成される場合や、画面外に出た後また画面内に戻ってくるような場合は使えません。

13
10
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
13
10