From the course: Unity 5: Network Gaming

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Adding a health indicator, part 3

Adding a health indicator, part 3 - Unity Tutorial

From the course: Unity 5: Network Gaming

Start my 1-month free trial

Adding a health indicator, part 3

- [Instructor] We need a way to show the health score on each player. There's several ways to do this. I usually use a really nice health bar I found on the Assets store, but while I'm prototyping, I usually just use a text box. This isn't visually perfect, but it's good enough for prototypes. Since I'm in the code, I think I'll go ahead and write the code for it first. I'm going to add a reference to the UI framework. So, using UnityEngine.UI. We're going to be using a text box, and in order to access the text box class, we're going to need a reference to the UI framework. Next, I'll go ahead and make a field to hold the text box, and I'll just call that HealthScore. Next, I'll go down to start and I'll go ahead and set Health Score's value as soon as the tank is instantiated. So, I'll say HealthScore.text equals current health. Next, I need to go down to TakeDamage and I need to set it here as well. I'll add it into the bottom of the else statement. That's it for the code. So, let's…

Contents