- Home /
GUI box not moving with game object on X axis
Hey,
I am trying to create a health bar above a spaceship in a 2d spaceshooter. Right now I just need to create a box and move it with the player. I found WorldToScreenPoint() which should work althought the box moves only on the Y axis, why is that?
This code is in Player.js attached to the ship gameobject
// Gui render
function OnGUI () {
var PlayerPosition : Vector2 = Camera.main.WorldToScreenPoint(transform.position);
print(PlayerPosition.x);
GUI.Box(new Rect(PlayerPosition.x, PlayerPosition.y, 200, 200), 'Test');
}
The print shows the changed position but the box only moves up and down.
Thanks!
Comment
Try using Unity UI. It hard to help people that are using old code.
Your answer
![](https://koobas.hobune.stream/wayback/20220612033826im_/https://answers.unity.com/themes/thub/images/avi.jpg)