- Home /
Setting ToolTip to Above Mouse Position
I'm putting a point and click game together, and I wanted my tooltip to show up over objects when the user points at them.
My tooltip recognizes objects just fine, saying the right names and appearing and all that, but I cannot get it to appear at mouse position.
Does anyone have any suggestions?
Answer by Justin Warner · Feb 01, 2011 at 07:38 PM
Get the position of the cursor, and use that + 100 on the Y or what not to get it above... Um,
var mousePos : Vector3 = Input.mousePosition;
And that'll get the X/Y and then you can just put the tool tip at the X/Y but add (I think UNity starts in the upper left corner, so it'd be subtract) 100, and it should work...
If that doesn't make sense, than ask!
Good luck!
That's great, all fixed now. I was using a GUIText, and so thought it would use a Vector2...doi.
I did have to convert that data into a ratio for the GUIText to interpret it, but that was just using the screen.width and screen.height which was nice and easy.
transform.position = objectPlace;
Answer by Mellemhund · May 25, 2011 at 06:56 PM
The Mouse seems to be inverted along the Y-axis - so to solve your problem try to do
Screen.height-mousePos.y
That put it right on the cursor for me!
Answer by Art Condelles · Feb 26, 2011 at 09:09 PM
Is there any possibility for the sake of someone who is not very well versed in scritping that you could maybe just go a touch deeper, I tried to implement this advice into my script and the position of the tooltip is at the bottom of the screen instead of by the cursor,this is the code I am using sorry if it seems remedial I am trying to learn on my own...
var mousePos: Vector3 = Input.mousePosition;
function OnGUI () { if (GUI.Button (Rect (10, 10, 100, 50), GUIContent("New Game", "Start a New Game"))) {
Application.LoadLevel (1);
}
GUI.Label (Rect (mousePos.x, mousePos.y - 100, 100, 20), GUI.tooltip);
}
Answer by Art Condelles · Feb 26, 2011 at 09:12 PM
Is there any possibility for the sake of someone who is not very well versed in scritping that you could maybe just go a touch deeper, I tried to implement this advice into my script and the position of the tooltip is at the bottom of the screen instead of by the cursor,this is the code I am using sorry if it seems remedial I am trying to learn on my own...
var mousePos: Vector3 = Input.mousePosition;</p> <p>function OnGUI () { if (GUI.Button (Rect (10, 10, 100, 50), GUIContent("New Game", "Start a New Game"))) {</p> <pre><code> Application.LoadLevel (1); } GUI.Label (Rect (mousePos.x, mousePos.y - 100, 100, 20), GUI.tooltip); </code></pre> <p>}
Answer by Art Condelles · Feb 26, 2011 at 09:13 PM
Sorry for double post I was trying to fix the code example
Your answer
Follow this Question
Related Questions
Tooltip and mouse position 4 Answers
Tracking the mouse off-window 1 Answer
IPointerEnterHander only fires on click 0 Answers
Inconsistent Mouse Related Behavior in 2D 1 Answer
How to find out which object is under a specific pixel 1 Answer