Access button text dynamially

Hi guys,

Is there anyway to access the text of a button in code?

Thanks :slight_smile:

Assuming you are using OnGUI and GUI.Button()

Yea, you will need to create the text object before hand. Then whenever you change that text object, it will update on the button automatically because of the reference.

string btnText = "Some Text";
Rect btnRect;

void OnGUI()
{
    GUI.Button(btnRect, btnText);
}