Creating Game Manager using Singleton pattern and MonoBehaviour in Unity3d

Here is another simple example of how you  game manager could be implemented with use of DontDestroyOnLoad()  and additional isActive()  method if it derives from MonoBehaviour.

I previous post we it was  explained how we can implement singleton pattern and persist its instance after reloading the scene. Now lets have a look at how we could take advantage of extending MonoBehaviour class and using DontDestroyOnLoad()  method.

Example shown in previous post provides easy access to all public properties and methods of GameManager singleton retrieved via GameManager.instance  property. This example however takes it to the next level, as you can now add public properties which you can modify directly from within Unity3d Editor.

Marek (admin)

Freelance developer, IT enthusiast, blogger with entrepreneurial spirit and passion for making games