- Home /
How can You Attach GUI text *above* a certain object?
How can You Attach GUI text above a certain object?
Like, above a player to show ranking and name.
Answer by Steffen Franz · Feb 17, 2011 at 07:48 PM
get the coordinates of the player in screen position http://unity3d.com/support/documentation/ScriptReference/Camera.WorldToScreenPoint.html
this returns you a x/y position on the screen, then place your text with an x and/or y offset to those coordinates.
I agree with this above solution, but I also just wanted to add as a quick alternate solution that 3D Text objects work for this too with the added benefit that placing them in 3D space requires far less scripting, the only problem being they look ugly up-close and draw on top of everything (even if the player has run behind a wall or something, which would have to be solved in a script).
Answer by vn1miguel · Mar 28, 2018 at 01:40 PM
I'm using a UI Text component but the solution can be used to Gui .
Code from Unity 2017.3.1f1
_bonusHit = Instantiate(_bonusHit, transform.position, Quaternion.identity);
_bonusHit.transform.SetParent(GameObject.Find("Canvas").transform, false);
_bonusHit.rectTransform.position = Camera.main.WorldToScreenPoint(transform.position);
Your answer
Follow this Question
Related Questions
How do you keep text inside miniCams 0 Answers
attaching armor to bone in proper position !!! help! 2 Answers
Camera rotation around player while following. 6 Answers
Distance along one axis? 1 Answer