Menu
CoddyTech

Hit Points

Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 62 of 71.

challenge icon

Challenge

Medium

Give the player hit points. The hunters' bite comes in the next lesson.

  1. In Health, add [SerializeField] private int hp = 3; and public void TakeDamage(int amount): take amount off hp and log "HP: " + hp.
  2. When hp reaches 0, log Game over and set GetComponent<Player>().enabled = false;.
  3. Start TakeDamage with if (hp <= 0) return;.

Press Play to see the waves come. Then Check.

Try it yourself

using UnityEngine;

public class Health : MonoBehaviour
{
    // A later lesson fills this in: the player's hit points.
}

All lessons in Physics and Gameplay

Practice on your own: Unity playground