3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Unity初級]this.gameObject.SetActive

Last updated at Posted at 2020-04-18

概要

自オブジェクトを消そうとした時、thisの記述をミスしました。備忘録として記事にします。

本文

オブジェクトが何かにぶつかったとき自分自身を画面から消すようなスクリプトを書こうとしましたがエラーになります。

    void OnCollisionEnter2D(Collision2D collision) {
        if (collision.gameObject.name == targetObjectName){
            this.SetActive(false);
        }

    }

gameObjectが無いと構文的におかしいものでした。

    void OnCollisionEnter2D(Collision2D collision) {
        if (collision.gameObject.name == targetObjectName){
            this.gameObject.SetActive(false);
        }

    }
3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?