LoginSignup
0
0

More than 3 years have passed since last update.

Unity:Componetの有効・無効を動的に切り替える

Posted at

はじめに

よく使う事があるのでメモ程度に残しておきます。

ソースコード

1つのモデルのColliderのON/OFFを切り替えた使った場合に、コンポーネンツの追加・削除を行うより、有効・無効を切り替えるほうがスマートかなと思ったのでその方法。

Monobehaviourを継承しているComponentにはenabledのプロパティがあるのでそれの切替。

GetComponent<BoxCollider>().enabled = false;

終わりに

よければ ブログ「Unity+AssetStoreおすすめ情報」の方にも色々記載しているのでぜひご参照いただければと思います。

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