//public int altura, largura; // Start is called before the first frame update public void Montar(int altura, int largura) { // Referenciaa de tamanho baseada no tamanho do prefab Vector3 refT = prefabParede[0].GetComponent <Renderer>().bounds.size; // Referencia de posição Vector3 refP = new Vector3(-2, 2, -1); string temp = GerarLabirinto.generateMaze(altura, largura); string[] strArray = temp.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // Quantidade de linhas no texto int linhas = strArray.Length; // Quantidade de colunas no texto int colunas = strArray[0].Length; // Pra cada linha... for (int l = 0; l < linhas; l++) { // Pra cada coluna... for (int c = 0; c < colunas; c++) { // Se o caracter correspondente for 1 if (strArray[l][c] == '1') { int rnd = Random.Range(0, prefabParede.Length); // Instancia o prefabParede numa nova posição igual ao tamanho do prefab vezes a linha mais a posição inicial, a mesma coisa pra coluna // Depois muda o nome pra representar isso Instantiate(prefabParede[rnd], new Vector3(refP.x + refT.x * l, 0, refP.y + refT.y * c), Quaternion.identity).name = "P_" + l + "_" + c; } else if (strArray[l][c] == '2') { Instantiate(item, new Vector3(refP.x + refT.x * l, 0, refP.y + refT.y * c), Quaternion.identity).name = "P_" + l + "_" + c; } else if (strArray[l][c] == '3') { GameObject pl = Instantiate(player, new Vector3(refP.x + refT.x * l, 0, refP.y + refT.y * c), Quaternion.identity); pl.name = "Player"; Camera.main.transform.position = pl.transform.position + new Vector3(0, 5, -5); Camera.main.transform.LookAt(pl.transform); Camera.main.transform.parent = pl.transform; } } } }
// Start is called before the first frame update void Start() { Vector3 refT = paredes[0].GetComponent <Renderer>().bounds.size; Vector3 refPosicao = new Vector3(-2, 0, -1); ///labirinto do texto /// TextAsset t = Resources.Load("meuTexto") as TextAsset; /// string[]str=t.text.Split(new char[]{ '\r','\n'}, /// StringSplitOptions.RemoveEmptyEntries); string temp = GerarLabirinto.generateMaze(20, 20); string[] str = temp.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);; int lin = str.Length; int col = str[0].Length; for (int l = 0; l < lin; l++) { for (int c = 0; c < col; c++) { if (str[l][c] == '1') { int rnd = Random.Range(0, paredes.Length - 1); GameObject obj = GameObject.Instantiate(paredes[rnd], refPosicao + new Vector3(refPosicao.x + refT.x * l, 0, refT.z * c), Quaternion.identity); obj.name = "Parede" + l + "_" + c; } } } /// { /// Instantiate(prefabParede, /// new Vector3(refP.x + refT.x * l, 0, /// refP.y + refT.y * c), /// Quaternion.identity).name="P"+l+"_"+c; /// } }
public void GerandoLabirinto() { Vector3 refT = prefabParede[0].GetComponent <Renderer>().bounds.size; Vector3 refP = new Vector3(-2, 0, -1); String temp = GerarLabirinto.generateMaze(colunaLabirinto, linhaLabirinto); string[] str = temp.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); int lin = str.Length; int col = str[0].Length; int item = (str.Length + str[0].Length) / 2; for (int l = 0; l < lin; l++) { for (int c = 0; c < col; c++) { if (str[l][c] == '1') { //int rnd = Random.RandomRange(0, prefabParede.Length ); if (varianteParede == 0) { GameObject obj = GameObject.Instantiate(prefabParede[varianteParede], new Vector3(refT.x * l, refP.y, refT.z * c), Quaternion.identity); obj.name = "P" + l + "_" + c; } if (varianteParede == 1) { GameObject obj = GameObject.Instantiate(prefabParede[varianteParede], new Vector3(refT.x * l, refP.y, refT.z * c), Quaternion.identity); obj.name = "P" + l + "_" + c; } if (varianteParede == 0) { varianteParede = 1; } else { varianteParede = 0; } } if (str[l][c] == '0') { int rndPickup = Random.RandomRange(0, item - 2); if (rndPickup == 1) { int rnd = Random.RandomRange(0, prefabPickup.Length); GameObject obj = GameObject.Instantiate(prefabPickup[rnd], new Vector3(refT.x * l, refP.y, refT.z * c), Quaternion.identity); obj.name = "P" + l + "_" + c; obj.transform.Rotate(new Vector3(90, 0, 0)); } GameObject objChao = GameObject.Instantiate(prefabChao, new Vector3(refT.x * l, refP.y - 0.90f, refT.z * c), Quaternion.identity); objChao.name = "Chao" + l + "_" + c; } if (c == 0 && l == 1) { startLocalition = new Vector3(refT.x * l, refP.y, refT.z * c); } if (c == col - 1 && l == lin - 2) { endLocation = new Vector3(refT.x * l, refP.y, refT.z * c); } } } startEnd(); prefabGrama.gameObject.SetActive(true); print("true"); }