Within the script of one game object I am initializing another game object with a prefab. To make development easier (so I don't have to run the game for every change) I call the function in OnValidate()
. Anytime I select the hasWindow
bool a Window clone is created. So in situations that I select then deselect (doesn't go away) and reselect, two clones are created. I don't even have a window game object in my hierarchy, so I don't get why any clone is created. I want the window to appear when I select hasWindow
and disappear (not hide) when I deselect within the inspector. How can I do this? The relevant code follows:
public bool hasWindow;
void OnValidate () {
prepareWindow();
}
void prepareWindow () {
if (hasWindow) {
window = (GameObject)Instantiate(Resources.Load("Prefabs/OtherPrefabs/Window"));
}
}