- Home /
Member variable not persistent
I have the following C sharp code:
private static bool show_gui;
public void showGUI(bool show)
{
show_gui = show;
Debug.Log ("show: " + show + " showgui: " + show_gui);
}
void OnGUI() {
bool guiBtnPushed = false;
Debug.Log ("showgui: " + show_gui);
}
I have the following output on console (collapsed):
show: False showgui: False
showgui: False
show: True showgui: True
As you can see, show_gui variable seemingly does not keep the 'true' value. What can go wrong?
Please post the rest of your code - in the extract shown you don't actually call showGUI()
What could go wrong is the order you expect the things to execute (at least thats a problem I had when testing GUI).
If you post more code, we could help you there.
tanoshirmi: showGUI is called from another place, with parameters true and false as well, as the console log shows Norax: I do not think the order really matters. As the console shows, ShowGUI() is called with 'true' and 'false'. After many ShowGUI calls with parameter 'true' the OnGUI() acts as if the value of show_gui was never changed.
Your answer
Follow this Question
Related Questions
Like PlayerPrefs but clears when game starts 2 Answers
Best way to persist data while we are in a not final version 4 Answers
Unity3D + Hibernate / Spring? 2 Answers
Canvas Button persistence 0 Answers