Hit Points
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 62 of 71.
Challenge
MediumGive the player hit points. The hunters' bite comes in the next lesson.
- In
Health, add[SerializeField] private int hp = 3;andpublic void TakeDamage(int amount): takeamountoffhpand log"HP: " + hp. - When
hpreaches 0, logGame overand setGetComponent<Player>().enabled = false;. - Start
TakeDamagewithif (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
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad4Coroutines
InvokeInvokeRepeating, CancelInvokeYour First CoroutineLoops in CoroutinesStopping CoroutinesRecap: Countdown10Project: Arena Escape
The ArenaHunters2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable WallPractice on your own: Unity playground