- Home /
Create tooltip on unity3d c#
Hai guys, i apologize if you think i asking a silly question. But i really don't know how to create tooltip when the mouse is hover the object like this image:
Could you guys give me some reference or an example? Thank you very much!
Answer by Fuhans · Nov 23, 2013 at 06:43 PM
Hai sir, i already could show the tooltip, but once i show the tooltip, the button function won't run.. why is it like that sir?
Here is the code:
public virtual void TurnOnGUI()
{
Rect textRect = new Rect(10, Screen.height - screenTextHeight, textWidth, textHeight);
Rect buttonRect = new Rect(0, Screen.height - buttonHeight * 3, buttonWidth, buttonHeight);
Rect _buttonRect = new Rect(0, Screen.height - buttonHeight * 2, buttonWidth, buttonHeight);
Rect _buttonRect_ = new Rect(0, Screen.height - buttonHeight * 1, buttonWidth, buttonHeight);
Rect tooltipRect = new Rect(100 + 10, Screen.height - buttonHeight * 3 + 5, buttonWidth, buttonHeight);
Rect _tooltipRect = new Rect(100 + 10, Screen.height - buttonHeight * 2 + 5, buttonWidth, buttonHeight);
Rect _tooltipRect_ = new Rect(100 + 10, Screen.height - buttonHeight * 1 + 5, buttonWidth, buttonHeight);
label1.normal.textColor = Color.red;
//Text Field
if (GUI.Button(textRect, ""))
{
}
//ToolTip Text
//GUI.Button(buttonRect, new GUIContent("Move", "Move the Player"));
//GUI.Label(tooltipRect, GUI.tooltip, label1);
GUI.tooltip = null;
//Move Button
if (GUI.Button(buttonRect, "Move"))
{
if (!moving)
{
GameManager.instance.RemoveTileHighlights();
moving = true;
attacking = false;
GameManager.instance.HighlightTilesAt(gridPosition, Color.blue, movementPerActionPoint);
}
else
{
moving = false;
attacking = false;
GameManager.instance.RemoveTileHighlights();
}
}
//ToolTip Text
//GUI.Button(_buttonRect, new GUIContent("Attack", "Attack the Player"));
//GUI.Label(_tooltipRect, GUI.tooltip, label1);
GUI.tooltip = null;
//Attack Button
if (GUI.Button(_buttonRect, "Attack"))
{
if (!attacking)
{
GameManager.instance.RemoveTileHighlights();
moving = false;
attacking = true;
GameManager.instance.HighlightTilesAt(gridPosition, Color.red, attackRange);
}
else
{
moving = false;
attacking = false;
GameManager.instance.RemoveTileHighlights();
}
}
//ToolTip Text
//GUI.Button(_buttonRect_, new GUIContent("End Turn", "End Turn the Player"));
//GUI.Label(_tooltipRect_, GUI.tooltip, label1);
GUI.tooltip = null;
//End Turn Button
if (GUI.Button(_buttonRect_, "End Turn"))
{
GameManager.instance.RemoveTileHighlights();
actionPoints = 2;
moving = false;
attacking = false;
GameManager.instance.NextTurn();
}
}
And here is the image (the tooltip has shown, but the "Move" button function won't run, won't show the blue grid for movement):
And when i delete the tooltip, the "Move" button function run perfectly as like shown at the image below:
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
On Mouse Click Button event 0 Answers
Unity C# Sockets? 2 Answers
Fog of War Explored Area Gray out / un-updated areas 0 Answers