From the course: Unity 5: Network Gaming

Unlock the full course today

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

Adding a health indicator, part 2

Adding a health indicator, part 2 - Unity Tutorial

From the course: Unity 5: Network Gaming

Start my 1-month free trial

Adding a health indicator, part 2

- [Instructor] In our collision handler, we need to detect whether or not what hit us was capable of causing damage. We don't really have anything like this set up on our projectile prefab, so we really should stop and think about that. The easiest thing would be to make a tag, then detect the tag. But a more elegant solution would be to detect whether a particular script exists on whatever hit us. That way, it would be possible for us to have the projectile tell the tank how much damage it can do. I'll find my projectile prefab in Assets. Select Add Component in the inspector, scroll all the way down, select New Script, and call it CauseDamage. Click Create and Add, and I'll open that in my code editor. In this script, I'll add a field to the top, and I'm just going to call it MaxDamage. And I'm going to set it equal to 10. And then I'm going to create a getter method. This isn't strictly necessary and I could get the value directly from the field, but a good practice here is to go…

Contents