(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TwoDimensions : MonoBehaviour
{
public GameObject[] blockPrefabs;
void Start()
{
int[][] blockImage =
{
new int[]{0,1,2,2,1,0},
new int[]{1,2,3,3,2,1},
new int[]{0,0,1,1,2,2,}
};
print(blockImage.Length);
print(blockImage[0].Length);
for (int i = 0; i < blockImage.Length; i++)
{
for (int j = 0; j < blockImage[i].Length; j++)
{
print(blockImage[i][j]);
if(blockImage[i][j] == 0)
{
Instantiate(blockPrefabs[0], new Vector3((j - 2.5f) + (0.5f * j), 0.5f, i + (0.5f * i)), Quaternion.identity);
}
else if(blockImage[i][j] == 1)
{
Instantiate(blockPrefabs[1], new Vector3((j - 2.5f) + (0.5f * j), 0.5f, i + (0.5f * i)), Quaternion.identity);
}
else
{
Instantiate(blockPrefabs[2], new Vector3((j - 2.5f) + (0.5f * j), 0.5f, i + (0.5f * i)), Quaternion.identity);
}
}
}
}
}
(実行結果)