Health Bar Part 1

Introduction – In this blog post I will be adding a health bar into my game, my tutor told me to follow this tutorial to cover some of the criteria for my assingment.

Sections
1) Health Bar tutorial

Health bar tutorial

I will be using InScope Studios youtube tutorials and I also paid for his health bar tutorial on pateron

Here is a link the patreon account that I brought his health bar tutorial packages https://www.patreon.com/posts/health-bar-4364337

Starting to implement

So what I’m going to do now is put the health bar into project folder and follow the tutorial setting up the health bar. Then from then on I can look at how I’m going to apply it to my player. Once I’ve added the health bar to the scene and get it too work then I can start properly implementing it in.

Now that I’ve added it I need to start adjust the mechanics of the bar, this is where I get stumped though. I need to use his code but make it my own.
how though. It worked in the example scene in the package but I’m having trouble getting it to work in my scene.

now the script has just broken for no reason? So I’m going to have to set the health bar up again

I’m confused because the code inside it has tests to see if the code is running like key w take 10 damage but it doesnt damage the script, it dont work. Even in the guys tutorial. I’m sure you can get it too work but its adding complex code into something, that still really confuses me.

How does the code work?

So what am I trying to solve here?
First of all I need to calm myself and think, this is a problem I need to solve. The health script I added in I deleted some of the code and only tried to set up the health bar ignoring the stamina bar. So what im going to do first of all is set up the values in the script properly and put this into the scene. Looking at the health bar scripts that I added in had small inconsistences in the code, fixing them now that I’m abit more confident at i’m going to try the original press onkeyenter press “W” function and see if it affects the health bar. It Didn’t affect it but my player moves forwared with the “w” key so im going to change the key to see if that affects the health bar. It didn’t so I decided to change the key being referenced to letter “R”.

This image has an empty alt attribute; its file name is image-12.png
This shows my health bars when I first put them into the scene so the code worked, deleting the lines of code like I did the first attempt breaks te
This shows the usage of the player script working with the health bar script
Animated GIF
Disabling the otehr stamina/energy bar and then testing the health bar by pressing the “R” key

Before breaking this down I have another game breaking bug, I saved and closed my project to work on the next day and now I am having this issue which I can’t seem to get past right now.
Everything in the console will not recognise any of my files and therefore the game will not run because none of the logic is being used. So I am going to look up the error that I am getting and see how to fix it.

https://forum.unity.com/threads/solved-the-referenced-script-on-this-behaviour-is-missing.381611/
This link talk about the same issues that I’m having and that it is a common error with unity and it means that the scene has somehow become corrupted.

https://forum.unity.com/threads/cant-add-script-component.632746/

Assembly reference point

How does the health bar work?
I still don’t truly understand what logic or how to add it in. Maybe this is because I still don’t understand the script.

The three main scripts
1) Player
2) BarScript
3) Stat

Player script –

What will be in the next part?
In conclusion –

Leave a comment

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started