Display a GUI.Label in the mouse position


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?


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, ...);