読者です 読者をやめる 読者になる 読者になる

peroon's diary

game programmer

Unity 二次元配列 サンプルコード

using UnityEngine;
using System.Collections;

public class testScript : MonoBehaviour {

    public GameObject cube;
    public GameObject[,] stage;

    // Use this for initialization
    void Start () {
        stage = new GameObject[2, 2];

        stage [0, 0] = Instantiate (cube, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
        stage [0, 1] = Instantiate (cube, new Vector3 (1, 0, 0), Quaternion.identity) as GameObject;
        stage [1, 0] = Instantiate (cube, new Vector3 (0, 1, 0), Quaternion.identity) as GameObject;
        stage [1, 1] = Instantiate (cube, new Vector3 (1, 1, 0), Quaternion.identity) as GameObject;

        stage [0, 0].renderer.material.color = Color.red;
        stage [1, 1].renderer.material.color = Color.red;
    }
    
    // Update is called once per frame
    void Update () {
    }
}