Problem with position of health bar

Hi,

I managed to get the enemy health bar on screen, but the position of the health bar is not where it should be. I also saw that when I select the enemy (as you can see in the screenshot) this red, green, blue thing is not at the same position as the selected enemy.

On the rightside of the screenshot you can see a white cross, that is where my enemy-healthbar is located. Really strange!

Does someone know what I’m doing wrong?

Hi,
I’ve run into the same problem. It seems that in Unity 2017 instantiated canvas has not set the transform to zero vector.

This is how I’ve managed it:

  1. Created new script on the Enemy Canvas Game Object.
  2. In the Start() method I’ve used this code:
    RectTransform rt = this.GetComponent();
    rt.anchoredPosition = Vector3.zero;

Edit: You should get the component “RectTranform”. Strange - It removes it from my message. Attaching the screenshot :slight_smile:

RectTransform

Best,
Piotr

7 Likes

Thank you so much! This needs to added to the video! It was driving me crazy.

Of course this was fast workaround to get this to work. I’m pretty sure there are better ways to fix it :slight_smile:

I also had this problem, thanks for the fix! The video could do with an update for 2017.

Thanks.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms