O'Reilly logo

Mastering Unity Scripting by Alan Thorn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding singleton objects and statics

Some classes are fundamentally different from others in the way they should be instantiated. Most classes define a template for a collection of properties and behaviors that might be instantiated many times in a scene as GameObjects. An enemy class can be used to instantiate many enemy objects, a power-up class for many power-up objects, and so on. However, some classes such as GameManager, HighScoreManager, AudioManager, or SaveGameManager are intended to exist as a lone entity, one that consolidates a unified set of behaviors. In short, there should only ever be one instance of the class at any one time and never more than one. To have more than one instance would either be nonsensical or damage the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required