public IEnumerator tileBuilder(Vector3 origin, tileManagerMode mode, int selector, int count, Queue <int> colorTiles) { switch (selector) { case 0: parent = (GameObject)Instantiate(neonTiles[colorTiles.Peek()], Ltiles.tileBricks[0] + origin, Quaternion.Euler(mode.getBO())) as GameObject; parent.GetComponent <TileScript>().setColoresPadre(colorTiles); colorTiles.Dequeue(); foreach (Vector3 v in Ltiles.attachPoints) { tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = " attach " + v.x; } foreach (Vector3 v in Ltiles.tileBricks) { int rnd = UnityEngine.Random.Range(0, 5); if (!v.Equals(Ltiles.tileBricks[0])) { tileElement = (GameObject)Instantiate(neonTiles[colorTiles.Dequeue()], Vector3.zero, Quaternion.identity) as GameObject; tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = "L " + v.x; } } triggerBox = parent.AddComponent <BoxCollider>(); triggerBox.size = Ltiles.triggerSize; triggerBox.center = Ltiles.triggerCenter; triggerBox.isTrigger = true; tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(Ltiles.powerUp[2]); tileElement.transform.localPosition = Ltiles.powerUp[0]; tileElement.transform.localScale = Ltiles.powerUp[1]; yield return(parent); break; case 1: parent = (GameObject)Instantiate(neonTiles[colorTiles.Peek()], Itiles.tileBricks[0] + origin, Quaternion.Euler(mode.getBO())) as GameObject; parent.GetComponent <TileScript>().setColoresPadre(colorTiles); colorTiles.Dequeue(); foreach (Vector3 v in Itiles.attachPoints) { tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = " attach " + v.x; } foreach (Vector3 v in Itiles.tileBricks) { int rnd = UnityEngine.Random.Range(0, 5); if (!v.Equals(Itiles.tileBricks[0])) { tileElement = (GameObject)Instantiate(neonTiles[colorTiles.Dequeue()], Vector3.zero, Quaternion.identity) as GameObject; tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = "I " + v.x; } } triggerBox = parent.AddComponent <BoxCollider>(); triggerBox.size = Itiles.triggerSize; triggerBox.center = Itiles.triggerCenter; triggerBox.isTrigger = true; tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(Itiles.powerUp[2]); tileElement.transform.localPosition = Itiles.powerUp[0]; tileElement.transform.localScale = Itiles.powerUp[1]; yield return(parent); break; case 2: parent = (GameObject)Instantiate(neonTiles[colorTiles.Peek()], Btiles.tileBricks[0] + origin, Quaternion.Euler(mode.getBO())) as GameObject; parent.GetComponent <TileScript>().setColoresPadre(colorTiles); colorTiles.Dequeue(); foreach (Vector3 v in Btiles.attachPoints) { tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = " attach " + v.x; } foreach (Vector3 v in Btiles.tileBricks) { int rnd = UnityEngine.Random.Range(0, 5); if (!v.Equals(Btiles.tileBricks[0])) { tileElement = (GameObject)Instantiate(neonTiles[colorTiles.Dequeue()], Vector3.zero, Quaternion.identity) as GameObject; tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = "B " + v.x; } } triggerBox = parent.AddComponent <BoxCollider>(); triggerBox.size = Btiles.triggerSize; triggerBox.center = Btiles.triggerCenter; triggerBox.isTrigger = true; tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(Btiles.powerUp[2]); tileElement.transform.localPosition = Btiles.powerUp[0]; tileElement.transform.localScale = Btiles.powerUp[1]; yield return(parent); break; case 3: parent = (GameObject)Instantiate(neonTiles[colorTiles.Peek()], Stiles.tileBricks[0] + origin, Quaternion.Euler(mode.getBO())) as GameObject; parent.GetComponent <TileScript>().setColoresPadre(colorTiles); colorTiles.Dequeue(); foreach (Vector3 v in Stiles.attachPoints) { tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = " attach " + v.x; } foreach (Vector3 v in Stiles.tileBricks) { int rnd = UnityEngine.Random.Range(0, 5); if (!v.Equals(Stiles.tileBricks[0])) { tileElement = (GameObject)Instantiate(neonTiles[colorTiles.Dequeue()], Vector3.zero, Quaternion.identity) as GameObject; tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = "S " + v.x; } } triggerBox = parent.AddComponent <BoxCollider>(); triggerBox.size = Stiles.triggerSize; triggerBox.center = Stiles.triggerCenter; triggerBox.isTrigger = true; tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(Stiles.powerUp[2]); tileElement.transform.localPosition = Stiles.powerUp[0]; tileElement.transform.localScale = Stiles.powerUp[1]; yield return(parent); break; case 4: parent = (GameObject)Instantiate(neonTiles[colorTiles.Peek()], Ttiles.tileBricks[0] + origin, Quaternion.Euler(mode.getBO())) as GameObject; parent.GetComponent <TileScript>().setColoresPadre(colorTiles); colorTiles.Dequeue(); foreach (Vector3 v in Ttiles.attachPoints) { tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = " attach " + v.x; } foreach (Vector3 v in Ttiles.tileBricks) { int rnd = UnityEngine.Random.Range(0, 5); if (!v.Equals(Ttiles.tileBricks[0])) { tileElement = (GameObject)Instantiate(neonTiles[colorTiles.Dequeue()], Vector3.zero, Quaternion.identity) as GameObject; tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(mode.getBO()); tileElement.transform.localPosition = v; tileElement.name = "T " + v.x; } } triggerBox = parent.AddComponent <BoxCollider>(); triggerBox.size = Ttiles.triggerSize; triggerBox.center = Ttiles.triggerCenter; triggerBox.isTrigger = true; tileElement = new GameObject(); tileElement.transform.SetParent(parent.transform); tileElement.transform.localRotation = Quaternion.Euler(Ttiles.powerUp[2]); tileElement.transform.localPosition = Ttiles.powerUp[0]; tileElement.transform.localScale = Ttiles.powerUp[1]; // Las T se marcan como bifurcaciones parent.GetComponent <TileScript>().setSimonBifurcado(true); parent.GetComponent <TileScript>().setSimonBifurcado(true); yield return(parent); break; default: yield return(null); break; } }
public void Spawner() { while (semaforoCutre == true) { ; } semaforoCutre = true; int rndPrefab = Random.Range(0, tilePrefabList.Length); tilesQue.Enqueue(tilePrefabList[rndPrefab]); index++; counter++; GameObject aux = currentTile; int randomBuilder = Random.Range(0, 5); if (counter < 8) { int rnd = Random.Range(0, 3); Vector3 posOrigin = aux.transform.GetChild(rnd).position; currentTile = (GameObject)Instantiate(tilesQue.Dequeue(), posOrigin, Quaternion.Euler(stageMode.getBO())); currentTile.name = "Tile " + index; // Marcamos el modo de juego y establecemos tanto el apdre como el punto de anclaje que será el destino de la nueva ficha currentTile.transform.GetComponent <TileScript>().setMode(stageMode.getNameAndKey()); currentTile.GetComponent <TileScript>().setTile(aux); currentTile.GetComponent <TileScript>().setAttachIndex(rnd); //Con un 10% de probabilidad spawneamos el power up y nunca en el bloque en el que caemos if (Random.Range(0.0f, 1.0f) <= 0.2f && !currentTile.GetComponent <TileScript>().getLandTile()) { if (nextNumber == -1) //Primera ejecucion { int aleatorio = Random.Range(0, 3); if (aleatorio == 0) //PowerUp Salto { GameObject powerUP = Instantiate(listaPowerUps[0], currentTile.transform.GetChild(9).transform.position, currentTile.transform.GetChild(9).transform.rotation); powerUP.GetComponent <saltoPowerUp>().tileAsociado = currentTile; //Generamos un número aleatorio entre 1 y 2 para seleccionar cual será el próximo power up nextNumber = Random.Range(1, 3); } else if (aleatorio == 1) //PowerUp disminuir velocidad { if (GameObject.Find("Player").GetComponent <scirp>().velocidadReducida == false) { Instantiate(listaPowerUps[1], currentTile.transform.GetChild(9).transform.position, currentTile.transform.GetChild(9).transform.rotation); } nextNumber = Random.Range(1, 3); if (nextNumber == 1) { nextNumber = 0; } } else if (aleatorio == 2) { if (GameObject.Find("Player").GetComponent <scirp>().cegado == false) { Instantiate(listaPowerUps[2], currentTile.transform.GetChild(9).transform.position, currentTile.transform.GetChild(9).transform.rotation); } nextNumber = Random.Range(0, 2); } } else { int aleatorio = Random.Range(0, 3); if (aleatorio == 0 && nextNumber == 0) //PowerUp Salto { GameObject powerUP = Instantiate(listaPowerUps[0], currentTile.transform.GetChild(9).transform.position, currentTile.transform.GetChild(9).transform.rotation); //Asociamos el game object de la pieza en la que esta el powerup powerUP.GetComponent <saltoPowerUp>().tileAsociado = currentTile; //Generamos un número aleatorio entre 1 y 2 para seleccionar cual será el próximo power up nextNumber = Random.Range(1, 3); } else if (aleatorio == 1 && nextNumber == 1) //PowerUp disminuir velocidad { if (GameObject.Find("Player").GetComponent <scirp>().velocidadReducida == false) { Instantiate(listaPowerUps[1], currentTile.transform.GetChild(9).transform.position, currentTile.transform.GetChild(9).transform.rotation); } nextNumber = Random.Range(1, 3); if (nextNumber == 1) { nextNumber = 0; } } else if (aleatorio == 2 && nextNumber == 2) { if (GameObject.Find("Player").GetComponent <scirp>().cegado == false) { Instantiate(listaPowerUps[2], currentTile.transform.GetChild(9).transform.position, currentTile.transform.GetChild(9).transform.rotation); } nextNumber = Random.Range(0, 2); } } } } else if (counter >= 8) { int attachPos; // Comprobamos que modos son compatibles con el actual if (stageMode.getCollindantModes().Count == 1) { // Esto implica que solo tiene conexión por su izquierda, de modo que el attach // a tener en cuenta es el 3 hijo attachPos = 3; Vector3 posOrigin = currentTile.transform.GetChild(attachPos).position /* + new Vector3(0.0f, 4.0f, 0.0f)*/; currentTile = (GameObject)Instantiate(tilesQue.Dequeue(), posOrigin, Quaternion.Euler(stageMode.getCollindantModes()[0].getBO())); currentTile.GetComponent <TileScript>().setMode(stageMode.getCollindantModes()[0].getNameAndKey()); updateStageMode(stageMode.getCollindantModes()[0].getNameAndKey()); } else { // Al tener también la posibilidad de generarse al frente, se decide de form aleatoria attachPos = Random.Range(3, 6); Vector3 posOrigin = currentTile.transform.GetChild(attachPos).position /*+ new Vector3(0.0f, 4.0f, 0.0f)*/; if (attachPos == 3) { currentTile = (GameObject)Instantiate(tilesQue.Dequeue(), posOrigin, Quaternion.Euler(stageMode.getCollindantModes()[0].getBO())); currentTile.GetComponent <TileScript>().setMode(stageMode.getCollindantModes()[0].getNameAndKey()); updateStageMode(stageMode.getCollindantModes()[0].getNameAndKey()); } else { currentTile = (GameObject)Instantiate(tilesQue.Dequeue(), posOrigin, Quaternion.Euler(stageMode.getCollindantModes()[1].getBO())); currentTile.GetComponent <TileScript>().setMode(stageMode.getCollindantModes()[1].getNameAndKey()); updateStageMode(stageMode.getCollindantModes()[1].getNameAndKey()); } } currentTile.tag = "Changer"; currentTile.name = "CamChanger Tile " + index; currentTile.transform.GetComponent <TileScript>().setMode(stageMode.getNameAndKey()); currentTile.GetComponent <TileScript>().setTile(aux); currentTile.GetComponent <TileScript>().setAttachIndex(attachPos); counter = 0; } //currentTile.transform.SetParent(GameObject.Find("ListaHijos").transform); currentTile.transform.SetParent(GameObject.Find("ListaHijos").transform); colaTilesActivos.Enqueue(currentTile); semaforoCutre = false; }