- Home /
Display a GUI.Label in the mouse position
Hi;
I want to show the player's gained point when the player hovers the mouse over the health bar. I want to show this value using a gui.label. and my health bar is also a gui.texture. I use this line to define my rect which is later used in my onGUI function to draw the label: myText = Rect(Input.mousePosition.x, Input.mousePosition.y, 20, 20);
The problem is that the label is shown in the same x with mouse but upper than the mouse. Actually it works like a mirror when I move my mouse upper the label comes near. Would you please help me what is the problem and how can I have a label just where my mouse cursor is?
Thanks.
Answer by Chronos-L · Jun 10, 2013 at 09:24 AM
Input.mousePosition's origin (0,0) is at the bottom-left, while Rect's at the top-left. You can use Screen.height to calculate the correct y for the label.
//This should be right, I am too lazy to test this
... Rect(Input.mousePosition.x, Screen.height-Input.mousePosition.y, ...);
Your answer
Follow this Question
Related Questions
How to get the number of lines in a GUI.Label by setting a max width. 2 Answers
How to use line break for GUI.Lable 1 Answer
how to accomplish:"When click a button , four button occour ." 0 Answers
Error with gun aim to the mouse 1 Answer
How to project the mouse cursor into 3D space for LookAt? 1 Answer