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 - Unity Tutorial
From the course: Unity 5: Network Gaming
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Project overview3m 15s
-
(Locked)
Set up the Network Manager2m 11s
-
(Locked)
Network identity3m 1s
-
(Locked)
Testing the game3m 46s
-
(Locked)
Network transform6m 58s
-
(Locked)
The local player6m 26s
-
(Locked)
Instantiate projectiles6m 58s
-
(Locked)
Firing projectiles6m 5s
-
(Locked)
Multplayer projectiles5m 2s
-
(Locked)
Adding a health indicator, part 12m 53s
-
(Locked)
Adding a health indicator, part 23m 44s
-
(Locked)
Adding a health indicator, part 34m 46s
-
(Locked)
Multiplayer health5m 54s
-
(Locked)
Fragging the enemy5m
-
(Locked)
Respawning6m 14s
-
(Locked)
-