Creating A Proper Game Manager

I am trying to learn how to use a game manager properly or some other solution. From what I understand, I store things in it that are not just variable to the one scene, or may want to be recapped latter.

For example I cant find any answer on how to rig Unity.UI to the game manager properly. I end up with more than one instance of a game manager due to scenes loading.

How do I work around this? This seems to not be a common topic of discussion. What is the proper way to do this, because I understand that their are many ways to get the job done. What way is the best?

This entire issue is

#INCREDIBLY OUT-OF-DATE

There’s just nothing to it these days …

CLICK HERE for an explanation -

it is dead simple. There’s just nothing to it.

If you do want to use the Grid.cs script - note that the only benefit is you save typing ONE line of code - just go here for the latest version …

Cheers.

@Fattie: Thanks for elaborating all this, it’s great!

There is a point though that people are trying to get through to you, and I’ll just give it a go as well, and since this is spread across to StackOverflow, forgive me a double post, but I think this is rather important to know for newbees specially since this post is high in Google ranking:

Having a “Preload” is a very good tip etc. But you take a step further, and there’s an issue there.

We do not want every instantiation of everything in our mobile games to do a “FindObjectOfType” for each and every every “global class”!

Instead you can just have it use an Instantiation of a static / a Singleton right away, without looking for it!

And it’s as simple as this: Write this in what class you want to access from anywhere, where XXXXX is the name of the class, for example “Sound”

public static XXXXX Instance { get; private set; }
void Awake()
{
if (Instance == null) { Instance = this; } else { Debug.Log("Warning: multiple " + this + " in scene!"); }
}

Now instead of your example

Sound sound = Object.FindObjectOfType<Sound>();

Just simply use it, without looking, and no extra variables, simply like this, right off from anywhere:

Sound.Instance.someWickedFunction();

You don’t need a prefab of the GameManager.
Just put the script on an object in your first scene.

make the script a singleton, and make sure to add "DontDestroy(gameObject);
this will make it so the object will stay alive between scenes, which means you don’t need to place it in every scene.

that being said… if you want to test other scene without loading the first scene, then you’ll need to place the gameManager in each scene (but remember to remove/disable it later)