I have a GameObject in Unity, which I've attached this script to, in order to make it function as a Static Singleton :
using UnityEngine;
using System.Collections;
public class SceneStatics : MonoBehaviour {
private static SceneStatics instance;
public static SceneStatics Instance
{
get
{
if (instance == null)
{
instance = new GameObject ("SceneStatics").AddComponent<SceneStatics> ();
DontDestroyOnLoad(instance);
}
return instance;
}
}
public void OnApplicationQuit ()
{
instance = null;
}
}
I have two other scripts that I'd like to be able to access from scene to scene. What's the proper way to do that?
Do I attach my Inventory and Room scripts to the same game object as the SceneStatics? If so, how do I access them? Can I go from SceneStatics.Instance to one of the other scripts directly via GetComponent?
Alternatively, what happens if I add two child gameObjects (each containing one of the other scripts) to the SceneStatics?
Or is the intended use that I simply make any other static items I need properties of the SceneStatics class? (I.e., add in a Public static Inventory and Public static Room attributes)?