- Home /
Keep GUIText in a relative position for different devices
I have GUIText in the top lefthand corner of my app. On the iPhone, it looks great, but it's basically centered when on an iPad. I could move it to display correctly on the iPad, but then I'd have the same problem when using a smaller screen... Any work arounds?
Answer by Lttldude · Apr 18, 2012 at 03:12 AM
Real simple actually. Just have the position of the GUIText be based on the camera viewport.
var viewportPosition : Vector3; //Vector3(0,0,0) I think is bottom left, don't worry about the z position
function Update ()
{
transform.position = Camera.main.ViewportToWorldPoint(viewportPosition);
}
Hope this helps.
EDIT: To find the correct viewport position. Add this to Update function and move to desired position and the viewport position will print in console.
print(Camera.main.WorldToViewportPoint(transform.position));
Your answer
Follow this Question
Related Questions
GUIText - how to set letter spacing? 2 Answers
How to display text using javascript ? 1 Answer
what is the correct way to display text on screen 1 Answer
GUIText not following player 1 Answer