Created
September 6, 2016 12:57
-
-
Save takoyakiroom/21cb952ef0261e66c45b20e12e5e1a8d to your computer and use it in GitHub Desktop.
迷路
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Maze : MonoBehaviour | |
{ | |
public GameObject Unbrk; // 壊れない奴 | |
public GameObject Brk; // 壊れるやつ | |
public GameObject Grnd; // 地面 | |
public GameObject Bomb; // 爆弾 | |
Vector3 block; // 1ブロックのサイズ用 | |
// マップデータ | |
// 0:なにもない 1:壊れない 2:壊れる | |
int[,] MazeData = new int[, ] { | |
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1 }, | |
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, | |
}; | |
void Awake() | |
{ | |
block = Unbrk.transform.localScale; // ブロックサイズ | |
Quaternion quat = Quaternion.Euler(0, 0, 0); | |
for (int x = 0; x < MazeData.GetLength(1); x++) | |
{ | |
for (int z = 0; z < MazeData.GetLength(0); z++) | |
{ | |
if (MazeData[z, x] == 1) | |
{ | |
// 壊れない | |
Instantiate(Unbrk, new Vector3(-x * block.x, block.y / 2, block.z * z), quat); | |
Instantiate(Unbrk, new Vector3(-x * block.x, -block.y / 2, block.z * z), quat); | |
} | |
else if (MazeData[z, x] == 2) | |
{ | |
// 壊れる | |
Instantiate(Brk, new Vector3(-x * block.x, block.y / 2, block.z * z), quat); | |
Instantiate(Unbrk, new Vector3(-x * block.x, -block.y / 2, block.z * z), quat); | |
} | |
else | |
{ | |
// 何もない | |
Instantiate(Grnd, new Vector3(-x * block.x, -block.y / 2, block.z * z), quat); | |
} | |
} | |
} | |
} | |
void Start() | |
{ | |
// プレイヤーの開始位置 | |
GameObject player = GameObject.Find("[CameraRig]"); | |
Vector3 pos = player.transform.position; | |
// 外周は壁なのでずらす | |
pos.x = -block.x; | |
pos.z = block.z; | |
// 位置移動 | |
player.transform.position = pos; | |
} | |
void Update() | |
{ | |
} | |
// 爆弾置く | |
public void PutBomb(Vector3 pos) | |
{ | |
Quaternion quat = Quaternion.Euler(0, 0, 0); | |
// 何ブロック目か | |
int x = (int)(-(pos.x - block.x/2) / block.x); | |
int z = (int)((pos.z + block.z/2) / block.z); | |
// 何もないところに置ける | |
if (MazeData[z, x] == 0) | |
{ | |
// ブロックの中心に爆弾を作る | |
Instantiate(Bomb, new Vector3(-x * block.x, -block.y / 2, z * block.z), quat); | |
} | |
Debug.Log("PutBomb x,z=" + x + "," + z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment