- Home /
Change the name of a toolbar button by clicking it. How?
Hello,
how can I change the name of a toolbar button, when I clicking it?
For instance:
I have a button called "Pause". If I´m clicking it, the game will freeze and the Button-Name is changing to "Resume". If I´m clicking the Button "Resume", the game will continue and the button-name is changing to "Pause". And so on.
I know how to write a button with 2 functions (like pausing and resuming the game), but changing the name of the button? I really don´t know, how to do it.
Can someone help me?
Answer by Baste · Oct 17, 2014 at 10:22 PM
Disclaimer: I'm assuming you're using GUI.Button.
The solution to your problem is to send in the Button's text as a variable rather than just writing it out. So it'd be something like:
string buttonText;
bool isPaused = false;
void Start() {
buttonText = "pause";
}
void OnGUI() {
if (GUI.Button(new Rect(...), buttonText)) {
if(isPaused) {
isPaused = false;
buttonText = "pause";
} else {
isPaused = true;
buttonText = "play";
}
}
}
That'll make a button that switches text as you press it. Hope that helps!
I´m using toolbar-function and I want it written in JavaScript
Your answer
Follow this Question
Related Questions
Return name of file only 1 Answer
"Name (Clone) (Clone) = Name" change? 2 Answers
How to change pace by pressing different buttons once? 1 Answer
How to change OnTriggerEnter to Ui Button click 1 Answer
If child.name == String problem 1 Answer