Search Unity

Strange problem with Floating HealthBar

Discussion in 'Scripting' started by Remer, Mar 19, 2018.

  1. Remer

    Remer

    Joined:
    Mar 24, 2013
    Posts:
    79
    Hello,
    I have a strange problem with the healthbar, as you can see, when I move the camera, or the object moves, the bar is badly positioned relative to the enemy (in this case, it's too far to the right).

    Code (CSharp):
    1.  
    2. Vector3 targetPos = canvasRoot.transform.position + Camera.main.transform.rotation * Vector3.forward;
    3. Vector3 targetOrientation = Camera.main.transform.rotation * Vector3.up;
    4. canvasRoot.transform.LookAt(targetPos, targetOrientation);
    5.  
     

    Attached Files: