Menu
CoddyTech

Enemies Strike Back

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 53 of 64.

challenge icon

Challenge

Medium

Make the enemies hit back.

  1. Hero implements IDamageable, health starting at maxHealth: a hit takes amount off, logs Hero HP: 4 and ignores hits for safeTime.
  2. At 0, log The hero falls, set enabled = false and ignore later hits.
  3. Enemy keeps the hero's IDamageable; within 1.2 units it calls TakeDamage(damage), at most once every attackEvery seconds.

Press Play and let a grunt reach you. Then Check.

Try it yourself

public interface IDamageable
{
    void TakeDamage(int amount);
}

All lessons in Game Architecture in Unity

Practice on your own: Unity playground