protected override void onTargetReached(GameObject obj) { TDWorld world = TDWorld.getWorld(); GameObject player = world.getPlayer(); if (obj == player) { TDPlayer tdP = world.getTDPlayer(); tdP.receiveDamage(1); } DestroyObject(gameObject); }
void OnDestroy() { Destroy(m_healthBar); if (OnEventDestroy != null) { OnEventDestroy(this); } TDWorld world = TDWorld.getWorld(); if (world == null) { return; } TDPlayer player = world.getTDPlayer(); if (player == null) { return; } player.reward(killReward()); }
// 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); } } } } } }