I'm new to Unity and C# so bear with me please. I have several scenes where the player can move at will and in one there are imageobjects that I want hidden when mouseclicked. Right now I have added a script to one imageobject where I use renderer.enabled = false;
to hide it. When the player moves back to that scene it is not hidden anymore. What would be the right way to do this?
//------EDITED PART----------- Now it works :)
public static bool showIt = true;
void Start () {
renderer.enabled = showIt;
print (showIt);
}
void OnMouseDown (){
showIt = false;
renderer.enabled = showIt;
}
Why don't you use static variables to persist the objects's state? You could use PlayerPrefs, but it's not the optimal method. Set your boolean variable to record the state using static initialization, then use your Start() method to initialize your variable and set the value(s). Remember before your LoadLevel() you must persist the value to the the given variable (or PlayerPrefs.Set* if you go that route). Remember if you persist in Update() or OnGUI() or FixedUpdate() there is significant cost.