LoginSignup
3
4

More than 3 years have passed since last update.

【Unity】public static な変数をインスペクター上で表示する (実行前のみ編集可能)

Posted at

対象

シングルトンを使うのが面倒だけど、public staticな変数をインスペクター上で表示・実行前に編集したい人

やり方

public static な変数に対して、[SerializeField] private の変数をセットで宣言し、void Awake() 内で代入するだけになります。

[SerializeField]
private GameObject objTemp;

public static GameObject obj;

void Awake () {
    obj = objTemp;
}

Awake() 内で代入しているため、実行中にインスペクターから変数をいじっても反映されません。

3
4
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
4