x


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?

more ▼

asked Apr 18 '12 at 02:27 AM

valichm gravatar image

valichm
136 19 22 27

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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));
more ▼

answered Apr 18 '12 at 03:12 AM

Lttldude gravatar image

Lttldude
1.2k 1 2 7

thank you!

Apr 18 '12 at 03:43 AM valichm
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x313
x83
x12

asked: Apr 18 '12 at 02:27 AM

Seen: 690 times

Last Updated: Apr 18 '12 at 03:43 AM