Menu
CoddyTech

Power-Ups

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

challenge icon

Challenge

Medium

Let the hero pick up hearts through one interface.

  1. In IPickup.cs, declare void Collect(Hero hero);.
  2. Heart implements IPickup: Collect calls hero.Heal(amount) and destroys the heart.
  3. In Hero, public void Heal(int amount) adds up to maxHealth and logs Hero HP: 4; OnTriggerEnter calls Collect(this) on an IPickup it 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

Practice on your own: Unity playground