Setting tooltip text depending on condition

Hello,

Wondering if anyone can help me solve a problem concerning tooltips. I have a character screen and a tooltip at the bottom of the screen to explain the label/button the player has the mouse over. This is working fine, but I’d like to have the text change depending on certain conditions present in the scene.

Example

// Speed + Button
if(GUI.Button(new Rect(x, y, a, b), new GUIContent("", "Increases Character Speed"), "StatButton")
{
	// Condition satisfied
	if(freeAttributePoints > 0)
	{
		// No need to show a message, just leave the button GUI content
	}
	
	// Condition not satisfied
	else
	{
		// Show a different message on tooltip, i.e. No free attribute points
	}
}

How I’m declaring tooltip:

// ToolTip Label
GUI.Label(new Rect(0, tooltipYPos, tooltipWidth, tooltipHeight), GUI.tooltip, "ToolTip");

Thanks for reading!

You could make the tooltip text a variable:

string tooltip = “Increases Character Speed”;

then when the button is clicked and the condition is met, replace it with a different value:

tooltip = “a different message on tooltip”;

You would display your button like this:

// Speed + Button
if (GUI.Button(new Rect(x, y, a, b), new GUIContent("", tooltip), "StatButton"))
{
    // Condition satisfied
    if (freeAttributePoints > 0)
    {
        // No need to show a message, just leave the button GUI content
    }

    // Condition not satisfied
    else
    {
        // Show a different message on tooltip, i.e. No free attribute points
        tooltip = "a different message on tooltip";
    }
}