LoginSignup
3

More than 1 year has passed since last update.

Unity パラメータ専用クラスを内部クラスとして作成

Posted at

0.0 はじめに

内部クラスをパラメータ化するときに少し手間取ったのでメモしておきます。

1.0 内部クラス

Monsterクラスが内部クラスで、パラメータとしてMonster Name、HP、MP、Attack、Defenseを持っています。

test.cs
public class Test : MonoBehaviour {

    public Monster[] monsters;

    [System.Serializable]
    public class Monster { // 内部クラス

        public string monsterName;
        public int HP;
        public int MP;
        public int Attack;
        public int Defense;

    }
}

👍ポイント 
[System.Serializable]を付ける。
内部クラスのアクセス因子はpublic、またパラメータもpublicの必要があります。

2.0 Inspector

Inspector(インスペクタ)上では下記のようになっています。
Sizeで種類数を設定します(1)
最初の項目にStringを使うと項目名がそのまま表示できます(2)

image.png

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