Sorry n00b question - scripts are usually attached to objects in a scene, but how do we handle scripts that persist from scene to scene - i.e. an overall game controller that is responsible for remembering progress, showing the menus, changing scenes etc.
What would I attach this script to?
An object in the scene, typically an empty game object.
–Eric
You can do what Eric said and attach it to an empty game object, but if you want to get your hands dirty a bit with C# you can use a singleton class. Basically it is a class that can only exist once in an instance of an application. You would not have to ever add it to your scene, but you may be limited to only coding in C# for your project as I don’t know how or if javascript or boo can access c#. I know c# cannot access javascript classes very easily, if at all. But if you are confident in your coding skills, look into singletons. Check the link below for more info on how to create one.
http://www.unifycommunity.com/wiki/index.php?title=Singleton
You can use DontDestroyOnLoad to persist a gameobject across scenes.
Thanks ShiftyMcCan - I’m using C# exclusively anyway, and I have built/used singletons in the past, so I may go that way.
I was just under the impression that when my scene was destroyed (before the next is created) the garbage collector would clear out all existing objects, including singletons - the first call to create the singleton would be from within this first scene, and when the scene is destroyed wouldn’t we lose the handle to it, thus the garbage collector would destroy it?
Sorry Eagle32 - you are quite right. Exactly what I need. I hadn’t seen your post there! Thanks
Ah. Well I am glad I was able to point you in the right direction. I have seen that DontDestryOnLoad function before but never knew what it was for. I’m sure that will come in handy for me too in the near future, so thanks for the info Eagle!