// Update is called once per frame void Update() { TDWorld world = TDWorld.getWorld(); TDPlayer tdPlayer = world.getTDPlayer(); if (tdPlayer.health() <= 0) { Application.LoadLevel("GameOver"); } if (Mode.eNone == m_mode) { return; } if (Input.GetMouseButtonDown(0)) { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(mouseRay, out hit)) { if (hit.transform.gameObject.Equals(GameObject.Find("Terrain"))) { Vector3 pos = hit.point; pos = TDWorld.getWorld().truncate3d(pos); GameObject newTower = null; if (TDGrid.CellState.eFree == world.positionState(pos)) { switch (m_mode) { case Mode.eArcher: if (!world.canTowerBeBuiltAt(pos)) { break; } newTower = world.addTower(TDTower.Type.eArrowTower, pos); break; case Mode.eCanon: if (!world.canTowerBeBuiltAt(pos)) { break; } newTower = world.addTower(TDTower.Type.eCanonTower, pos); break; case Mode.eHeroPatrol: TDHero tdHero = world.getTDHero(); tdHero.patrol(pos); break; default: return; } if (newTower != null) { TDTower tdTower = world.getTDTower(newTower); if (!tdPlayer.affords(tdTower.price())) { DestroyObject(newTower); return; } tdPlayer.expense(tdTower.price()); TDWorld.getWorld().occupyPosition(pos, TDGrid.CellState.eBusy); } } } } } }