How to fix position of Health bar above enemy to always?

I want fix position GUI Texture of Health bar on head enemy always.
because i used camera.WorldToScreenPoint, gui move to camera then position of bar not to same.

image problem

notice position of health bar isn’t same.

I want to same image below

http://dl.dropbox.com/u/63979073/WebPlayerMechGameStarterPack/WebPlayer.html

How to script fix position please? :face_with_spiral_eyes:

Your problem might be in:

  1. Camera.WorldToScreenPoint returns pixell coordinates, but the Y axis is starting from the bottom-left screen edge. You need to convert is to “GUI” coordinate system - starting at top-left:
var target : Transform;
function Update () {
    var screenPos:Vector3 = camera.WorldToScreenPoint (target.position);
    var x = screenPos.x;
    var y = Screen.height - screenPos.y;
    print ("x=" + x + "; y=" + y);
}
  1. You didn’t add any offset to your texture. If you want your texture to be above the 3D object, you need to subtract some fixed or dynamic value:
var target : Transform;
var xOffset: float;
var yOffset: float;
function Update () {
    var screenPos:Vector3 = camera.WorldToScreenPoint (target.position);
    var x = screenPos.x - xOffset; // x offset
    var y = Screen.height - screenPos.y - yOffset; // y offset
    print ("x=" + x + "; y=" + y);
}

Great, that solved my problem! :slight_smile:

@dkozar
Oh Yeah! Thank You.

NP, glad I can help. Unity really overcomplicated with multiple coordinate systems… :slight_smile: