Scripting like POO

Hello guys!
I was trying to do one thing, but i couldn’t.
Something like, when i press on button in one script this button changes the state of one bool variable in other script,

if(createButton(620, 500, 100, 30, "Confirm")) {
Instruments.showContentInstrument = true;
}

The variable in the other script it’s obviously static! And about the createButton(it is a method that i created, corresponding GUI.Button(new Rect…), “”);
I wanna to press the button and change the state, and in the other script he will verify if the bool variable is true, like this:

if(showContentInstrument == true) {
			if(createButton(620, 400, 100, 30, "Trompete")) {
				trompClicked = true;
			}

Thanks to all that will help =).

1 Answer

1

I’m wondering if your createButton method returns a bool or not? If it doesn’t return the result of GUI.Button then it isn’t going to register a button press. It should look something like this…

bool Button(Rect rect, string text)
{
    return GUI.Button(rect, text);
}

yea, i did that!

Please post comments by pressing the 'add new comment' button, not by posting a new answer. Great! So your code looks good to me (except checking that a bool is == true). Does your second button show up like it's supposed to? You don't really state what problem you're having is, only what your intended behavior is.

Ryan, this will (obviously) prevent the last frame from clearing, plus the background will start as black. Most people most likely don't want this behavior.