Unityで二次配列を使ってマップを作るやつ。よく忘れるのでメモ。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MAP : MonoBehaviour
{
public GameObject kabe;
public GameObject jimen;
public GameObject st;
int[,] map = new int[,] {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{ 1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1},
{ 1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1},
{ 1,0,0,0,1,0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,1,0,1},
{ 1,0,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1},
{ 1,0,1,0,0,0,0,0,1,0,1,0,1,1,1,1,0,0,0,1,0,0,0,1},
{ 1,0,1,1,1,1,1,0,1,0,1,0,0,1,1,1,0,1,1,1,1,1,1,1},
{ 1,0,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,0,1,1,1,1,1},
{ 1,0,1,1,1,1,1,0,0,0,1,1,1,0,1,1,1,1,0,1,1,1,1,1},
{ 1,0,1,0,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1},
{ 1,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1},
{ 1,0,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1},
{ 1,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1},
{ 1,1,1,0,1,0,1,0,0,0,0,0,1,1,1,1,1,1,0,1,1,1,1,1},
{ 1,0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1},
{ 1,0,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
{ 1,0,0,0,1,0,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1},
{ 1,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1},
{ 1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1},
{ 1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1},
{ 1,0,0,0,0,1,0,0,0,0,0,0,1,1,2,1,1,1,1,1,0,0,0,1},
{ 1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1},
{ 1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1},
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
// Start is called before the first frame update
void Start()
{
for (int i= 0;i< 24; i++){
for (int j = 0; j < 24; j++)
{
if (map[i,j] ==0) { Instantiate(jimen, new Vector3(i * 1, 0, j * 1), transform.rotation); }
if (map[i,j] ==1) { Instantiate(kabe, new Vector3(i * 1, 1, j * 1), transform.rotation); }
if (map[i, j]==2) { Instantiate(st, new Vector3(i * 1, 0, j * 1), transform.rotation); }
}
}
}
// Update is called once per frame
void Update()
{
}
}