Problem of resolution with floating health bar

Hi

I have another problem with changes of resolution : as the image shows i have a very simple floating health bar over a turret in my tower defence project, if i play with the default resolution (in the left) the bar appears where is supposed to but if i change the resolution, it’s y axis is totally messed up (right of the image) and the difference gets bigger if i move the camera forward. This is the code i use so i already covered the problem with the y coordinates that happens when you use WorldToScreenPoint.

auxPosition = Camera.main.WorldToScreenPoint(currentTurret.gun.transform.position);

//Health Bar
GUI.DrawTexture(new Rect(auxPosition.x - 25, Screen.height - auxPosition.y, 50, 5), damageTexture, ScaleMode.StretchToFill);
GUI.DrawTexture(new Rect(auxPosition.x - 25, Screen.height - auxPosition.y, ((float)currentTurret.currentHealth / (float)currentTurret.baseHealth) * 50.0f, 5), healthTexture, ScaleMode.StretchToFill);

Now, i know there are alternative solutions (like using a texture in the world space) but i want to give a last shot to this to see if there’s any solution, so please if somebody has any idea please share it.

Thanks.

Ok, apparently the problem is caused by the “GUI.matrix = Matrix4x4.TRS…” stuff (wich is kind of ironic because i use that line to solve the same problem with the other gui elements) so i put the line after the code and the health bar now is located where is supposed to be. Of course this give me another problems but at least i now know the origin of the problem.