- Home /
Problem with GUI element following enemy
Hello guys I'm experiencing a little problem while setting a ui element to follow the enemies. Basically the UI object moves with the enemy , but the movement is based on the position of the camera and on the PoV. If the enemy is in the middle of the screen the button is centered, but if the enemy is on the right the button is on the left and if it's on the left, the button is on the right. Notice I'm just talking about the x, the y is fine
enemy on the right of the camera:
enemy on the left of the camera:
and this is the code I'm using:
Vector3 screenPos = Camera.main.WorldToScreenPoint(unit.transform);
button.tranform.position = screenPos;
thanks a lot
Where is the anchor of your button located? Certainly there is nothing wrong with your code.
the anchor is centered. Also the bar moves when I zoom in and out (but on the y this time)
Your answer
Follow this Question
Related Questions
Can I do a "rotatory" UI like this? 1 Answer
What is the right choice for UI Performance? 0 Answers
Is there still have the old UI color theme in Unity 3 Pro? 2 Answers
Converting OnGUI function to UI 1 Answer
Interface relative scaling 0 Answers