Week 11:
Learning How To Use Unity Engine – Part 5:
So, with the Player and Enemy NPC out of the way I now need to focus on a few things which’ll include the following; Player Health, Roaming NPC and Taking Damage. First, I’ll work on the Health Bar. In order to do this, I went into my “Scripts” folder and then I created a new “C# Script” that I named “Health Manager”. I then selected my “Player” and then created a “Canvas” using “UI”, which I renamed “HUD”. Using the “UI”, I then created a “Text” box. And finally, I used the “UI” to create two “Images” I named “Bottom Layer” and “Top Layer”.

Afterwards, I then began to put the two “Images” in the top right corner, which I then reshaped into rectangle-like shapes. I made the “Bottom Layer” a “Red” colour and the “Top Layer” a “Green” colour. In the “Image (Script” for the “Top Layer”, I then changed the following; “Image Type” > “Filled”, “Fill Method” > “Horizontal” and finally “Fill Origin” > “Left”. This, basically, means when my “Player” begins to lose health in game the colour will start to turn from green to red from the left side.
In the “Image (Script” for the “Top Layer”, I then changed the following; “Image Type” > “Filled”, “Fill Method” > “Horizontal” and finally “Fill Origin” > “Left”. This, basically, means when my “Player” begins to lose health in game the colour will start to turn from green to red from the left side.
I used and edited the following coding to use for my script. Basically, this piece of scripting will work in tandem with another script. The piece of coding here basically shows the max health on the “HUD” and when the other code kicks in, will show when the “Player” is damaged. Once I was done with the script, I then saved it and dragged the “Health Manager (Script)” to the “HUD”. I then set the following; “Image Health Bar” > “Top Layer (Image)”, “Min” > “0” and “Max” > “100”.