Updating the player's health

In this section, we will fully implement our player's health. We will start the Cucumber Man with three lives, each with a full health value of 100. We will update our scripts so that the Cucumber Man loses health when a cucumber beetle attacks him. Our approach will be to deduct one point from the Cucumber Man's health for every second that it is colliding with a Cucumber Beetle. We will also script the HUD's health bar and start with that task in the next section.

Before we get started, you should open your Unity game project. Alternatively, you can download the Starting-Chapter-11 Unity project available from the publisher's companion site.

Get Getting Started with Unity 2018 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.