- Home /
Make GUItext appear on screen at location of collision
My camera has a width of 10, ranging from -5 to 5 on the x axis in the scene view, and in-game my player can move from -5 to 5 on the x axis and collide with objects. When the player collides with certain objects I'd like some GUItext to appear on-screen at the position of that collision displaying a number. GUItext's X-axis values range from 0 to 1, however, so instantiating the GUItext with a position of gameobject.transform.position from the collision does not display the text where I would like on the in-game screen.
I have a feeling that I'm going to have to figure out the math to translate my in-scene -5 to 5 x-axis to 0 to 1 for the GUItext, but is there a way that I can easily do this?
Answer by robertbu · May 07, 2014 at 09:33 PM
GUITexts live in Viewport space. Your objects in World space. To convert between the two, you can use Camera.WorldToViewportPoint(). Something like:
theText.position = Camera.main.WorldToScreenPoint(hit.point);
Your answer
Follow this Question
Related Questions
can my player collide with more than one objects? 1 Answer
How can I keep track of score without each new basketball shot reseting the points? 0 Answers
Displaying Text On touch 2 Answers
How can I keep track of score without each new basketball shot reseting my points? 1 Answer
How to make a static box display message on collision 1 Answer