// Update is called once per frame void Update() { AudioListener.volume = mute ? 0 : 1; switch (gameState) { case GameStates.Play: //get the grid the mouse is over Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(mouseRay, out hit, 1000, 1 << 8)) { HexController hex = hit.transform.gameObject.GetComponent(typeof(HexController)) as HexController; hex.startMoving(.4f, 2f, true, true); if (Input.GetMouseButtonDown(0)) { if (hex.tower == null && !hex.path) { if (buildSelection >= 0) { selection = spawnTower(hex, towers[buildSelection]); money -= towers[buildSelection].upgrades[0].cost; towerSelection = towers[buildSelection].type; buildSelection = -1; } else { selection = null; towerSelection = -1; } } else if (hex.tower != null) { selection = hex.tower; towerSelection = hex.tower.type; } else { selection = null; towerSelection = -1; } } } if (Input.GetMouseButtonDown(1)) { buildSelection = -1; towerSelection = -1; } if (Input.GetKeyDown(KeyCode.Alpha1)) { buildSelection = 0; } if (Input.GetKeyDown(KeyCode.Alpha2)) { buildSelection = 1; } if (Input.GetKeyDown(KeyCode.Alpha3)) { buildSelection = 2; } if (Input.GetKeyDown(KeyCode.Alpha4)) { buildSelection = 3; } if (Input.GetKeyDown(KeyCode.Alpha5)) { buildSelection = 4; } if (Input.GetKeyDown(KeyCode.E) && selection != null && selection.upgradeLevel + 1 < selection.upgrades.Length) { upgradeTower(selection, 1); } if (Input.GetKeyDown(KeyCode.Space)) { startWave(); } if (Input.GetKeyDown(KeyCode.F)) { Time.timeScale = Time.timeScale == 1 ? 2 : 1; } if (Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.Escape)) { Time.timeScale = 0; gameState = GameStates.Pause; } if (health <= 0) { gameState = GameStates.GameOver; Time.timeScale = 0; } break; case GameStates.Pause: if (Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.Escape)) { gameState = GameStates.Play; Time.timeScale = 1; } break; } }