Is it possible say to have a timer on a slide out UI panel not destroy when a scene changes? For instance if I have a trip timer and I set the timer, then slide the panel with the timer on it out of view, then I go to another scene and then come back to that scene have the trip timer continue keeping accurate time?
Hopefully I explained that right?
You say you tried “a few variations” but it sounds you only tried setting the Panel to not be destroyed. I think the “DontDestroyOnLoad” only works with game objects at the top level of the hierarchy, if you set your Panel to not be destroyed but you let the Canvas containing it be destroyed, the Panel will be gone too.
Try calling the DontDestroyOnLoad for the Canvas or whatever is at the top level that contains the panel, every child of that object should still be there when you change the Scene.
Also, Neamtzu talked about making it a Singleton, but a singleton and something that is not destoyed when switching scenes are not the same thing. A singleton gameobject needs the DontDestroyOnLoad method, but you can keep anything from one scene to another even if they’re not intended to be singletons.
To stop the panel from being destroyed, write this
void Awake ()
{
DontDestroyOnLoad(this.gameObject);
}
and attach it to the Canvas of the panel because UI’s can only be visible if their in a Canvas parent.
The parent and the children won’t be destroyed when you load something