My health bar positions are off

My health bar locations are off unless unit is facing north.
Health bars are facing the camera. but not always on top of the units.
Without the FaceCamera script the hp bar always stay on top of my unit.

image

my code for facecamera.cs:
using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class FaceCamera : MonoBehaviour

{

// Start is called before the first frame update

Transform mainCameraTransform;

void Start()

{

    mainCameraTransform = Camera.main.transform;

}

// Update is called once per frame

void LateUpdate()

{

    transform.LookAt(

        transform.position + mainCameraTransform.rotation * Vector3.forward, 

        mainCameraTransform.rotation * Vector3.up);

}

}

HealthBar settings:

Hi there, my best guess is that this is related to how they are setup in the hierarchy, relative to the units. Can you show that?

Here are the screenshot for unit itself, inspector screen for Canvas, background, hp

Hi, so I see that the canvas is position at X = -0.4. Try making X = 0. Move the X Pivot to 0.5 if you need to. Let me know if that helps.

It worked! thanks

1 Like

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

Privacy & Terms