How to get button name from onGUI


How should I get the button name from the button that I created on onGUI. Example like how to get name “Click” on GUI.Button(new Rect(0,0,100,50), “Click”)

The best you can do is to store the text.

string textToDisplay = "Click";
GUI.Button(new Rect(0,0,100,50), textToDisplay);

Now you can access textToDisplay.

Well I guess you can always try just to make “click” a variable…

I guess you’re just a bit confused how the GUI system works. You don’t really “create” a button. OnGUI is called every frame and the GUI.Button function draws the button AND processes the input for this button. The function returns true when you clicked on the button.

Usually you use it this way:

// C#
void OnGUI()
    if (GUI.Button(new Rect(0,0,100,50), "Click"))
        // Do something when the button is clicked
        Debug.Log("Button 'Click' has been clicked");

Thanks for your reply… I doing friendship button and create button base on the number of user’s friendship she or he has from the database. I wondering how am I know which button is be pressed by user because is dynamic created.

One of the logic that I think of is trying to get the button name from the button. I not sure of other logic ArrayList?