What exactly is a singleton

what is it?

to put it into the most basic way possible, a singleton is a script (class) that only exists once in your game world.


the point is for any other script/class to be able to access that script/class and anything within it.
you do this by just typing the script name, ‘dot’, and then any variable you’d like to access within that script/class.


it is better to use singletons for a script that you will only have one copy of in your scene, as it’ll make it easier than referencing it a million times in other scripts.


so rather than using like:

public GameManager gameManager;

void Start()
{
     gameManager.points = 0;
}

//logic

you would only have to use:

void Start()
{
     GameManager.points = 0;
}

//logic

since it is now, a singleton.


helps organize your code alot, and prevents possible errors.