facebook twitter hatena line email

Unity/Csharp/配列

提供: 初心者エンジニアの簡易メモ
2017年9月22日 (金) 05:07時点におけるAdmin (トーク | 投稿記録)による版 (クラスディクショナリ)

移動: 案内検索

配列宣言

int[] nums;
float[] f;
Vector3[] v;
GameObject[] gameObjects;

数字配列宣言&入力

int[] nums = {10,20,30,40,50,60,70,80,90,100};

or

int[] nums = new int[10];
nums[0] = 10;
nums[1] = 20;
Debug.Log(nums[1]); // 20

文字列配列宣言&入力

string[] names = new string[] { "taro", "jiro", "saburo" };
Debug.Log(names[1]); // jiro

クラスリスト

List<Car> cars = new List<Car>();
cars.Add( new Car("Lexas", 50));

クラスディクショナリ

Dictionary<string, Car> cars = new Dictionary<string, Car>();
Car bg1 = new Car("Lexas", 50);
Car bg2 = new Car("Rx8", 100);
cars.Add("Lexas", bg1);
cars.Add("Rx8", bg2);
Car car = cars["Lexas"];

参考

公式リストとディクショナリ https://unity3d.com/jp/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries