Be the first to post for 'Enemy Floating Health Bar'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

Hi @Ben,

Where can we find the resource Health Bar v.2.unitypackage mentioned in this video? I’ve also noticed the last two videos are probably ordered wrong. Shouldn’t Player Health Bar UI be positioned before the Enemy Floating Health Bar lecture video?

2 Likes

Thanks for pointing this out, and for bearing with us as we get this early content straight. Both the attachments and the lecture ordering have been fixed.

2 Likes

3 Likes

I am unable to download the file attached to lesson 28 - Enemy Floating health Bar which is called “5_CC_RPG Enemy Health Bar v.2.zip”. I click it and it does nothing. Now I was able to get the file from the previous lesson a couple days ago but today I decided to try getting that one as well before posting here and I can’t get it either (it’s called " 4_CC_RPG Health Bar Package v.1.zip") and I tried in both Firefox and Chrome. I went up to a previous lesson and was able to grab the zip file form that one (using Raycasts to Query Click). So I think something is wrong with those two attachments.

edit seems to be working this morning, looks like two new files were uploaded

looking great man!

Thought going transparent would be cool for the player but not sure I like it for enemies… will probably change later.

Not committed to a art style yet, so just testing the waters right now.

1 Like

My instantiated health bar doesn’t rotate correctly, but if I place one on there manually, it works! Does anyone have any idea why that might be, or have you had this issue? I’m beat.

1 Like

Ben fixes this issue in another lecture.

2 Likes

Thanks, @Stephen_Crookes. Had me going bananas.

I made few changes to make the health bar look like this. Also I change I use lerp to change the color from green to red as the health bar goes to 0 and also I removed the rotation because i did not really want that oh well ^^ this is how it looks so far

Also I am going to make the health bar only appear when enemies get hit.

5 Likes

Help:
I am getting this error when following the directions to add the Floating Health Bar
NullReferenceException: Object reference not set to an instance of an object
EnemyHealthBar.Update () (at Assets/Enemies/EnemyHealthBar.cs:22)

I have tried logging the result of healthBarRawImage I get the following:

Null
UnityEngine.MonoBehaviour:print(Object)
EnemyHealthBar:Start() (at Assets/Enemies/EnemyHealthBar.cs:16)

Health Bar (UnityEngine.UI.RawImage)
UnityEngine.MonoBehaviour:print(Object)
EnemyHealthBar:Start() (at Assets/Enemies/EnemyHealthBar.cs:16)

I am not sure why I am getting two print statements… almost like it is running start twice (only one enemy) on screen)

If I comment out:
healthBarRawImage.uvRect = new Rect(xValue, 0f, 0.5f, 1f);
in the EnemyHealthBar script the code runs but I assume this will mean the health bar will not change.

I do see a floating health bar above my enemy when I do comment out that line.

I am running MonoDeveloper and Unity 5.5.1f1 Personal (64bit) on a windows 10 PC.

@Tom_McLaughlin, the nullReferenceException on that line would indicate that healthBarRawImage is null.

Do you have a RawImage component on the Enemy Canvas?

I did but that got me thinking…the code is actually referencing enemy so I added a raw image to enemy and it is running now… I will have to wait to I get through some more content to see if it works as it is suppose to… thanks

@Tom_McLaughlin I could be wrong but it sounds like your EnemyHealthBar script is on your enemy in that case? I have the script on the rawimage childed to the enemy canvas.

1 Like

Fantastic…that was the problem (ish) I actually had it on the Enemy and the health bar… that would explain the two print results and one case being null and the other not… As soon as I deleted the script from the Enemy I was able to delete the extra raw image component and vola it all works as it is done in the lesson… Thank you!!!

1 Like

The rotated health bar issue bugged me, so I came up with an alternative using a single Particle in the UI Socket with the healthbar image as Material. This way it is always rotated towards the camera (no rotation script), and the material’s x-offset can be used to show different health for each enemy. Showing both in the image for comparison.

1 Like

Finally made it to Lecture 30, lol. And for someone that has never used Unity or programming, these classes are amazing. But here it is in its glory. HEALTH BARS < cool! Game:Go over wall, fight, save people, bring the back over wall to safety.

4 Likes

@Martin The rotating health bar issue is cleared up pretty quickly and easily in one of the next few lectures

2 Likes

Privacy & Terms