[游戏开发-学习笔记]菜鸟慢慢飞(七)- 迷宫更新
随机迷宫,留下一个问题:
"Quaternion这个API看不懂,先放到学习清单中,如果会这个,应该就可以横墙,竖墙只用一个."
查看了下官方API。
只用一面墙,效果是一样的。
更新一下代码:
using UnityEngine; /// <summary> /// 初始化迷宫 /// </summary> public class InitializeMazerev1 : MonoBehaviour { public GameObject WallHS; public GameObject pillars; public int sumber = 100; // Use this for initialization void Awake() { int sidexy = sumber * 11; for (int i = 0; i < (sumber + 1); i++) { for (int j = 0; j < (sumber + 1); j++) { int pillarx = i * 110; int wallHx = 55 + 110 * i; int pillarz = j * 110; int wallVz = 55 + 110 * j; if (i == sumber && j == sumber) { Instantiate(pillars, new Vector3(pillarx, 50, pillarz), Quaternion.identity); continue; } if (i == sumber) { Instantiate(pillars, new Vector3(pillarx, 50, pillarz), Quaternion.identity); //Instantiate(WallV, new Vector3(pillarx, 50, wallVz), Quaternion.identity); Instantiate(WallHS, new Vector3(pillarx, 50, wallVz), Quaternion.Euler(0, 90, 0)); continue; } if (j == sumber) { Instantiate(pillars, new Vector3(pillarx, 50, pillarz), Quaternion.identity); Instantiate(WallHS, new Vector3(wallHx, 50, pillarz), Quaternion.identity); } else { Instantiate(pillars, new Vector3(pillarx, 50, pillarz), Quaternion.identity); Instantiate(WallHS, new Vector3(wallHx, 50, pillarz), Quaternion.identity); // Instantiate(WallV, new Vector3(pillarx, 50, wallVz), Quaternion.identity) Instantiate(WallHS, new Vector3(pillarx, 50, wallVz), Quaternion.Euler(0, 90, 0)); } } } } }