void Update() { Debug.Log("Health is: " + enemy.GetHealth()); // if (enemy.GetHealth() < 0) // { // Destroy(enemy.GetGameObject()); // } if (enemy.GetAttackState()) { // Destroy(hitTower.gameObject); // if (hitTower.NotDead()) // { // hitTower.SendMessage("AddHealth", -enemy.GetDamage()); // } } else { float step = speed * Time.deltaTime; // calculate distance to move if (towerTarget != null) { float distance = Vector3.Distance(transform.position, towerTarget.position); if (distance < 4.0f) { enemy.SetAttackState(true); } transform.position = Vector3.MoveTowards(transform.position, towerTarget.position, step); } else { transform.position = Vector3.MoveTowards(transform.position, new Vector3(90, 7, 90), step); } } }
public void AddHealth(int amount) { enemy.AddHealth(amount); if (enemy.GetHealth() < enemy.GetMaxHealth() && healthBar == null) { healthBar = Instantiate(healthBarPrefab, Game.progressCanvas.transform); healthBar.GetComponent <HealthScript>().healthable = enemy; } }