public void TakeDamage(int dmg) { if (dead == false) { health = health - dmg; healthBar.value = health; if (health <= 0) { scoreScript.AddScore(scoreWorth); scoreScript.AddGold(goldWorth); dead = true; //Destroy(this.gameObject); GetComponent <Animator>().SetBool("dead", true); } } }
public void PlaceTower() { if (scoreScript.GetGold() >= actualCost) { scoreScript.AddGold(-actualCost); bool placeable = true; for (int i = 0; i < towers.ToArray().Length; i++) { // Debug.Log(worldPoint.x +" "+ towers[i].transform.position.x); //if (worldPoint.x- archerTowerSizeX < towers[i].transform.position.x && worldPoint.x+ archerTowerSizeX > towers[i].transform.position.x // && worldPoint.y - archerTowerSizeY < towers[i].transform.position.y && worldPoint.y + archerTowerSizeY > towers[i].transform.position.y) { //placeable = false; // Debug.Log("cannot place"); //} //Debug.Log(towers[i].GetComponent<Rigidbody2D>().velocity.y ); if (towers[i].transform.position.y > highest - 5 && towers[i].GetComponent <Rigidbody2D>().velocity.y - 0.5 < 0 && towers[i].GetComponent <Rigidbody2D>().velocity.y + 0.5 > 0) { highest = towers[i].transform.position.y + hightInc; } //highest = highest + 0.f; } //Debug.Log(highest); if (placeable) { GameObject archerTowerObj = Instantiate(selectedTower, new Vector2(worldPoint.x, highest), transform.rotation); towers.Add(archerTowerObj); } StartCoroutine(WaitBetweenSpawns()); } else { //Debug.Log("cost too much"); } }