Is their a gameworld manager inside Unity?

Is their a gameworld manager inside Unity?

What im wanting to have is a global object that manages the game itself, but the game manager itself does nothing directly inside the game. It just keeps track of where objects are, create objects on timers, etc, etc.

So for example:


Would return the 4th created enemy.

You have to write something like this yourself.

Create a new C# script and call it GameWorldManager. Then give it a new attribute called enemies of type List. Make the class and the attribute static.

This is how your class should initially look like:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public static class GameWorldManager {

	public static List<GameObject> enemies = new List<GameObject>();


You don’t need to instatiate your GameWorldManager as it is a static class from which there is always exactly 1 instance. Because it does not derive from MonoBehaviour you can not (or lets better say: need not) attach it to a GameObject.

Now you can add, remove or access enemies from everywhere inside your project i.e. by saying

GameObject enemy6 = GameWorldManager.enemies[5];

(Note that the 5th enemy is actually referenced by enemies[4] because the first one is stored in position 0)

Hope this helps you further.