public void placeTeleport() { Vector3 teleportPosition = transform.position + transform.forward * 2.0f; if (teleportA == null) { teleportA = (GameObject)Instantiate(teleportInstance, teleportPosition, Quaternion.identity); teleportAScript = teleportA.GetComponentInChildren <CustomTeleporter>(); teleportAScript.teleportPadOn = false; } else if (teleportB != null) { Destroy(teleportA); teleportA = teleportB; teleportB = (GameObject)Instantiate(teleportInstance, teleportPosition, Quaternion.identity); teleportAScript = teleportA.GetComponentInChildren <CustomTeleporter>(); teleportBScript = teleportB.GetComponentInChildren <CustomTeleporter>(); teleportAScript.destinationPad.SetValue(teleportBScript.gameObject.transform, 0); teleportAScript.teleportPadOn = true; teleportBScript.destinationPad.SetValue(teleportAScript.gameObject.transform, 0); teleportBScript.teleportPadOn = true; } else { teleportB = (GameObject)Instantiate(teleportInstance, teleportPosition, Quaternion.identity); teleportAScript = teleportA.GetComponentInChildren <CustomTeleporter>(); teleportBScript = teleportB.GetComponentInChildren <CustomTeleporter>(); teleportAScript.destinationPad.SetValue(teleportBScript.gameObject.transform, 0); teleportAScript.teleportPadOn = true; teleportBScript.destinationPad.SetValue(teleportAScript.gameObject.transform, 0); teleportBScript.teleportPadOn = true; } }
public void placeTeleport() { Vector3 teleportPosition = transform.position + transform.forward * 2.0f; if (teleportA != null) { Destroy(teleportA); } teleportA = (GameObject)Instantiate (teleportInstance, teleportPosition, Quaternion.identity); teleportAScript = teleportA.GetComponentInChildren<CustomTeleporter>(); teleportBaseScript = BaseTeleport.GetComponentInChildren<CustomTeleporter>(); teleportAScript.destinationPad.SetValue (teleportBaseScript.gameObject.transform, 0); teleportAScript.teleportPadOn = true; teleportBaseScript.destinationPad.SetValue (teleportAScript.gameObject.transform, 0); teleportBaseScript.teleportPadOn = true; }
public IEnumerator Generate() { baseI = new Vector2(1, 7); //baseJ = new Vector2(size.z-1, size.z-7); baseJ = new Vector2(1, 7); /* * GameObject leftWall = GameObject.Find ("Long Wall Left"); * GameObject rightWall = GameObject.Find ("Long Wall Right"); * float leftNewZ = 100f + 2 * size.z; * float NewX = -2 * (size.x+1) + 0.2f; * float rightNewZ = -100f - 2 * size.z; * leftWall.transform.position = new Vector3 (NewX, leftWall.transform.position.y, leftNewZ); * rightWall.transform.position = new Vector3 (NewX, rightWall.transform.position.y, rightNewZ); */ player = GameObject.FindGameObjectWithTag("Player"); playerCharacterMotor = player.GetComponent <CharacterMotor> (); WaitForSeconds delay = new WaitForSeconds(generationStepDelay); cells = new MazeCell[size.x, size.z]; List <MazeCell> activeCells = new List <MazeCell>(); PlopBaseAtSide(); DoFirstGenerationStep(activeCells); while (activeCells.Count > 0) { //yield return delay; DoNextGenerationStep(activeCells); } playerCharacterMotor.movement.gravity = 9.81f; /* * for (int i = 0; i < golemAmount; i++) { * float randomX = Random.Range (-2 * size.x, 2 * size.x); * float randomZ = Random.Range (-2 * size.z, 2 * size.z); * Instantiate(golemInstance, new Vector3(randomX, DROP_DISTANCE, randomZ), Quaternion.identity); * * } */ GameObject exitCell = GameObject.Find("Maze Cell " + (size.x - 1) + ", " + (size.z - 2)); GameObject entryCell = GameObject.Find("Maze Cell " + (int)baseI.y + ", " + (int)(baseJ.x + 3)); GameObject otherSideOfEntryCell = GameObject.Find("Maze Cell " + (int)(baseI.y + 1) + ", " + (int)(baseJ.x + 3)); Destroy(exitCell, 0f); Destroy(entryCell, 0f); Destroy(otherSideOfEntryCell, 0f); for (int i = 0; i < potionAmount; i++) { float randomX = Random.Range(-2 * size.x, 2 * size.x); float randomZ = Random.Range(-2 * size.z, 2 * size.z); if (randomX < -2 * size.x + 32 && randomZ < -2 * size.z + 32) { float XorZ = Random.Range(0, 1); if (XorZ > 0.5) { randomX = Random.Range(-2 * size.x + 32, 2 * size.x); } else { randomZ = Random.Range(-2 * size.z + 32, 2 * size.z); } } randomX = Mathf.Floor(randomX); randomZ = Mathf.Floor(randomZ); if (randomX % 4 == 0) { randomX = randomX + 2; } if (randomZ % 4 == 0) { randomZ = randomZ + 2; } Instantiate(potionInstance, new Vector3(randomX, DROP_DISTANCE, randomZ), Quaternion.identity); } for (int i = 0; i < clockAmount; i++) { float randomX = Random.Range(-2 * size.x, 2 * size.x); float randomZ = Random.Range(-2 * size.z, 2 * size.z); if (randomX < -2 * size.x + 32 && randomZ < -2 * size.z + 32) { float XorZ = Random.Range(0, 1); if (XorZ > 0.5) { randomX = Random.Range(-2 * size.x + 32, 2 * size.x); } else { randomZ = Random.Range(-2 * size.z + 32, 2 * size.z); } } randomX = Mathf.Floor(randomX); randomZ = Mathf.Floor(randomZ); if (randomX % 4 == 0) { randomX = randomX + 2; } if (randomZ % 4 == 0) { randomZ = randomZ + 2; } Instantiate(clockInstance, new Vector3(randomX, DROP_DISTANCE, randomZ), Quaternion.identity); } for (int i = 0; i < teleportAmount; i++) { float randomX = Random.Range(-2 * size.x, 2 * size.x); float randomZ = Random.Range(-2 * size.z, 2 * size.z); if (randomX < -2 * size.x + 32 && randomZ < -2 * size.z + 32) { float XorZ = Random.Range(0, 1); if (XorZ > 0.5) { randomX = Random.Range(-2 * size.x + 32, 2 * size.x); } else { randomZ = Random.Range(-2 * size.z + 32, 2 * size.z); } } randomX = Mathf.Floor(randomX); randomZ = Mathf.Floor(randomZ); if (randomX % 4 == 0) { randomX = randomX + 2; } if (randomZ % 4 == 0) { randomZ = randomZ + 2; } GameObject t = (GameObject)Instantiate(teleportInstance, new Vector3(randomX, DROP_DISTANCE, randomZ), Quaternion.identity); CustomTeleporter s = t.GetComponentInChildren <CustomTeleporter>(); s.destinationPad = new Transform[teleportAmount - 1]; teleporterList.Add(t); } for (int i = 0; i < teleportAmount; i++) { GameObject t = (GameObject)teleporterList[i]; CustomTeleporter s = t.GetComponentInChildren <CustomTeleporter>(); int index = 0; for (int j = 0; j < teleportAmount; j++) { if (j != i) { GameObject target = (GameObject)teleporterList[j]; s.destinationPad.SetValue(target.GetComponentInChildren <CustomTeleporter>().gameObject.transform, index); index++; } } } for (int i = 0; i < crateAmount; i++) { float randomX = Random.Range(-2 * size.x, 2 * size.x); float randomZ = Random.Range(-2 * size.z, 2 * size.z); if (randomX < -2 * size.x + 32 && randomZ < -2 * size.z + 32) { float XorZ = Random.Range(0, 1); if (XorZ > 0.5) { randomX = Random.Range(-2 * size.x + 32, 2 * size.x); } else { randomZ = Random.Range(-2 * size.z + 32, 2 * size.z); } } randomX = Mathf.Floor(randomX); randomZ = Mathf.Floor(randomZ); if (randomX % 4 == 0) { randomX = randomX + 2; } if (randomZ % 4 == 0) { randomZ = randomZ + 2; } Instantiate(crateInstance, new Vector3(randomX, DROP_DISTANCE, randomZ), Quaternion.identity); } for (int i = 0; i < zombieAmount; i++) { float randomX = Random.Range(-2 * size.x, 2 * size.x); float randomZ = Random.Range(-2 * size.z, 2 * size.z); if (randomX < -2 * size.x + 40 && randomZ < -2 * size.z + 40) { float XorZ = Random.Range(0, 1); if (XorZ > 0.5) { randomX = Random.Range(-2 * size.x + 40, 2 * size.x); } else { randomZ = Random.Range(-2 * size.z + 40, 2 * size.z); } } randomX = Mathf.Floor(randomX); randomZ = Mathf.Floor(randomZ); if (randomX % 4 == 0) { randomX = randomX + 2; } if (randomZ % 4 == 0) { randomZ = randomZ + 2; } Instantiate(zombieInstance, new Vector3(randomX, DROP_DISTANCE, randomZ), Quaternion.identity); } for (int i = 0; i < skeletonAmount; i++) { float randomX = Mathf.Floor(Random.Range(-2 * size.x + 45, 2 * size.x)); float randomZ = Mathf.Floor(Random.Range(-2 * size.z + 45, 2 * size.z)); if (randomX % 4 == 0) { randomX = randomX + 2; } if (randomZ % 4 == 0) { randomZ = randomZ + 2; } Instantiate(skeletonInstance, new Vector3(randomX, DROP_DISTANCE, randomZ), Quaternion.identity); } for (int i = 0; i < monsterAmount; i++) { float randomX = Mathf.Floor(Random.Range(-2 * size.x + 50, 2 * size.x)); float randomZ = Mathf.Floor(Random.Range(-2 * size.z + 50, 2 * size.z)); if (randomX % 4 == 0) { randomX = randomX + 2; } if (randomZ % 4 == 0) { randomZ = randomZ + 2; } Instantiate(monsterInstance, new Vector3(randomX, DROP_DISTANCE, randomZ), Quaternion.identity); } mazeRangeCollider = gameObject.GetComponent <BoxCollider>(); yield return(new WaitForSeconds(0f)); }