Zombie Runner - Zombie Death Alternative

So in my challenge, I decided to use the EnemyHealth to broadcast a message, so that I didn’t need a new die method in that class.

public void TakeDamage(float damage)
    {
        if(hitPoints <= Mathf.Epsilon) { return; }

        hitPoints -= damage;
        BroadcastMessage("OnDamageTaken");
        if(hitPoints <= Mathf.Epsilon)
            BroadcastMessage("Die");
    }

Then back in EnemyAI everything else is managed. There’s an isDead bool that I added. But when “Die” is triggered in EnemyAI, this happens:

public void Die()
    {
        isDead = true;
        navMeshAgent.speed = 0;
        animator.SetTrigger("Dead");
        GetComponent<CapsuleCollider>().enabled = false;
    }

Originally I just set the navMeshAgent destination to the current position of the zombie, but I saw someone else post about setting speed to 0 and I thought that was even better/clearer. Disabling the capsule collider means you don’t bump into the dead (re-dead?) body. Finally in update I start the function off with a check to isDead and then return if true to avoid the other AI functionality before it starts.

It was fun to come up with something different than Rick that I’m pretty sure still works!

Privacy & Terms