public void Move() { MapController_script m = mapcontroller.GetComponent <MapController_script>(); //routePosition += speed * Time.deltaTime / 100; routePosition += speed / 3000; int currentRoutePositionInt = (int)Mathf.Floor(routePosition); int nextRoutePositionInt = currentRoutePositionInt + 1; if (nextRoutePositionInt >= m.route.Count) { foreach (GameObject tower in towers) { if (this.gameObject) { tower.GetComponent <Tower_script>().GetMonsters().Remove(this.gameObject); } } foreach (GameObject tower in towers) { tower.GetComponent <Tower_script>().GetMonsters().Remove(this.gameObject); } mapcontroller.GetComponent <MapController_script>().monsterHolder.Remove(this.gameObject); Destroy(this.gameObject); player.GetComponent <PlayerController_script>().addCurrentHP(-1); } else { Vector3 current = m.GetMapPosition(m.route[currentRoutePositionInt].i, m.route[currentRoutePositionInt].j, 0.5f); Vector3 next = m.GetMapPosition(m.route[nextRoutePositionInt].i, m.route[nextRoutePositionInt].j, 0.5f); float dec = routePosition - currentRoutePositionInt; Vector3 newPosition = next * dec + current * (1 - dec); transform.Find("Model").LookAt(next); this.transform.position = newPosition; } if (hp.Equals(0)) { //explo.Play(); foreach (GameObject tower in towers) { tower.GetComponent <Tower_script>().GetMonsters().Remove(this.gameObject); } mapcontroller.GetComponent <MapController_script>().monsterHolder.Remove(this.gameObject); //Debug.Log("123"); Destroy(this.gameObject); player.GetComponent <PlayerController_script>().addResource(reward); } }
public void Sell() { MapController_script mc = mapcontroller.GetComponent <MapController_script>(); player.GetComponent <PlayerController_script>().addCurrentResource(5); baseGrid.GetComponent <Grid_script>().availability = true; mc.SetAvailability(baseGrid, true); foreach (GameObject monster in mc.monsterHolder) { monster.GetComponent <Monster_script>().removeFromTowers(this.gameObject); } Destroy(this.gameObject); if (!mc.getInwave()) { mc.UpdatePath(); } }