// Use this for initialization void Start() { attack = GetComponent <Attack>(); hp = GetComponent <Hp>(); target = null; mode = TowerMode.DefaultAttack; }
public void EnemyReached(GameObject gameObject) { // If already attacking, ignore new enemy if (mode == TowerMode.Attack) { return; } mode = TowerMode.Attack; target = gameObject; hPBehavior = gameObject.GetComponent <HPBehaviour>(); arrowAnimation(); InvokeRepeating("AttackCycle", period, period); }
void AttackCycle() { // Enemy is dead if (hPBehavior == null) { CancelInvoke("AttackCycle"); mode = TowerMode.Watch; // Check if we can keep attacking var closeEnemy = FindCloseEnemy(); if (closeEnemy) { EnemyReached(closeEnemy); } return; // Enemy can be attacked } else { hPBehavior.decreaseHP(power); } arrowAnimation(); }