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);
    }
Example #2
0
    void OnCollisionEnter(Collision collision)
    {
        // on collision, means the enemy just reached an enemy it will have to attack
        // so, start its attacking cycle, until the collided building is dead or the enemy itself adies
        // (there's an extra condition in the future when the target gets far away somehow)


        var gameObject = collision.collider.gameObject;

        // Discard collision if not a building (or player, for testing) or already attacking
        var tag = gameObject.tag;

        if (tag != "Building" || mode == EnemyMode.Attack)
        {
            return;
        }

        mode        = EnemyMode.Attack;
        hPBehaviour = gameObject.GetComponent <HPBehaviour>();

        InvokeRepeating("AttackCycle", 0, period);
    }
 private void Start()
 {
     thisHP = GetComponent <HPBehaviour>();
 }