LoginSignup
0
0

More than 3 years have passed since last update.

Unity コンポーネントの有無を調べる方法

Posted at

ちょっと引っかかったのでメモ。

var component = object.GetComponent<Image>();

if(component == null)
{
   //メソッド
}

コンポーネントが無い場合にコンポーネントを追加する方法。

var component = object.GetComponent<Image>();

if(component == null)
{
   object.AddComponent<Image>();
}
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