Skip to content

shadegames/unity-singleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Unity Singleton

Unity singleton base class.

Setup

In order to use the Singleton class (which extends the MonoBehavior class), just import the Shade namespaace and extend your class that way:

using UnityEngine;
using Shade;

public class Game : Singleton<Game>
{
    void Start()
    {
        // Work your magic
    }
    
    public void SomeMethod()
    {
        // Anything can happen in a game, you are the wizard.
    }
}

As you can see, we are using the singleton pattern in the context of a game manager here.

Usage

Once your class is setup, you may retrieve your instance from anywhere in your scripts.

Game.instance.SomeMethod();

Credits

This class is a slightly modified version of the default singleton class available on Unity's community wiki.

About

Unity singleton base class.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages