O'Reilly logo

Mastering Unity 2017 Game Development with C# - Second Edition by Alan Thorn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comments

  • The PlayerHealth variable references the Health component on the player object. This variable is assigned during the Awake function by searching the scene for an object tagged as Player. Once found, the health component is retrieved. You can display health for other characters (such as zombies), however, by exposing the PlayerHealth field as public and manually assigning a reference to a different object.
  • The UpdateHealth function updates the Width of the health bar based on the health of the player. The RectTransform.sizeDelta variable controls the width of the health bar.
The UpdateHealth function can be called on every frame (such as in Update) to update the GUI health status. However, continually using update in this way is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required