Enemies Strike Back
Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 53 of 64.
Challenge
MediumMake the enemies hit back.
HeroimplementsIDamageable,healthstarting atmaxHealth: a hit takesamountoff, logsHero HP: 4and ignores hits forsafeTime.- At 0, log
The hero falls, setenabled = falseand ignore later hits. Enemykeeps the hero'sIDamageable; within 1.2 units it callsTakeDamage(damage), at most once everyattackEveryseconds.
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
1Components, Not Hierarchies
Small ComponentsA Base Enemy ScriptAbstract ComponentsComponents Working TogetherRecap: Modular TurretRecap: Twin Cannon4Serialized Data
Serializable ClassesLists in the InspectorEnums in the InspectorRecap: Loot TableRecap: Roll the Loot7State Machines
States as ClassesThe Alert StateA State MachineTransitionsEnemy BrainsThe Knight AttacksRecap: Door States10Project: Arena Survivor
The HeroEnemy Types2Interfaces in Unity
IDamageableInterfaces and TryGetComponentGetComponentsRecap: Interact KeyRecap: Nearest in ReachPractice on your own: Unity playground