How to create a GUI button with tooltip and intercept the click event?

Hello everyone, I’m new in Unity3d and have a question.I know how to create a button:

if (!btnTexture) {
Debug.LogError(“Please assign a texture on the inspector”); return;
}

This will display log if button clicked. I know how to add tooltip to a butto also:

GUI.Button(new Rect(10, 10, 100, 20), new GUIContent(“Click me”, “This is the tooltip”));
GUI.Label(new Rect(10, 40, 100, 40), GUI.tooltip);

The question is ,how can I create a GUI button with tooltip and intercept the click event? If use “if” statement,"GUI.Label " have no effect except the button being clicked.

With tooltip, or no tooltip - it’s the same (2 separate problems). The tooltip is the mouse-over thing, and button reacts on click.

For button click, you should wrap the button thing into the if statement:

if (GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", "This is the tooltip"))) {
    // button clicked. do something
}

However, in your case you need the additional check:

bool clicked = GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", "This is the tooltip"));
if (clicked) {
    if (btnTexture) {
        // button clicked. do something
    } else {
        Debug.LogError("Please assign a texture on the inspector");
    }
}