Join Kelley Hecker for an in-depth discussion in this video Introducing the singleton pattern, part of Scripting Unity with C#.
- A design pattern that's not specific to Unity…but is still very useful in the context of games…is the singleton pattern.…A singleton is a class that can only have one instance…at any given time,…and it can be accessed from any other class.…Singletons are often used to store a game state,…or for manager classes,…such as a class that manages all the user interface…or plays all of the audio for the game.…The singleton is a powerful design pattern…that is relatively easy to implement.…We're going to create a base singleton class…that you can use for all the singletons you make.…
You can start by creating a new C# Script called Singleton.…Double-click to open it.…Go ahead and remove Start and Update,…since we won't be needing them.…We'll start by changing the declaration of the class…to be generic, by adding T after the class name,…where T is a MonoBehaviour.…A generic class just means that we won't know…the type of T until run time.…
For example, a generic list can be made…to hold game objects or transforms or integers,…
- Defining classes and variables
- Attaching scripts to objects
- Understanding MonoBehaviour class
- Using the Unity Scripting API
- Importing assets
- Using a singleton pattern to manage game state
- Creating an event
Skill Level Intermediate
Advanced Unity 3D Game Programmingwith Michael House3h 45m Advanced
Creating Mobile Games with Unitywith Kelley Hecker1h 12m Intermediate
1. Your First Script
3. Built-In Unity Classes
Picking up coins4m 8s
5. Events and Delegates
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.