Power-Ups
Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 56 of 64.
Challenge
MediumLet the hero pick up hearts through one interface.
- In
IPickup.cs, declarevoid Collect(Hero hero);. HeartimplementsIPickup:Collectcallshero.Heal(amount)and destroys the heart.- In
Hero,public void Heal(int amount)adds up tomaxHealthand logsHero HP: 4;OnTriggerEntercallsCollect(this)on anIPickupit touches.
Press Play, take a hit and walk into the heart. Then Check.
Try it yourself
// A later lesson fills this in: anything the hero can pick up.
public interface IPickup
{
}
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