![]() |
VOOZH | about |
A singleton is a class that allows only one instance of itself to exist. Any script can access it from anywhere without needing a reference.
This is the simplest singleton pattern.
Now any script can call GameManager.Instance.StartGame() without finding or dragging references.
This version prevents duplicate instances from being created.
If a second AudioManager tries to spawn, it destroys itself. The first one remains.
Once you have a singleton, any script can access it directly. This is the main benefit - no dragging references in Inspector.
No need to drag references. Just call ClassName.Instance.MethodName() from anywhere.
| Singleton | Static Class |
|---|---|
| Inherits from MonoBehaviour | Cannot inherit from MonoBehaviour |
| Can use Unity methods (Start, Update) | No Unity lifecycle methods |
| Can be placed in the scene | Cannot be placed in the scene |
| Supports DontDestroyOnLoad | No scene persistence |