AManagerClass

From Unify Community Wiki
Jump to: navigation, search

Warning: This script is incomplete and outdated. Use the superior Singleton base class instead.

AManager.cs

 
// Author: Keli Hlodversson (freyr)
 
using UnityEngine;
 
public class AManager : MonoBehaviour
{
    // s_Instance is used to cache the instance found in the scene so we don't have to look it up every time.
    private static AManager s_Instance = null;
 
 
    // A static property that finds or creates an instance of the manager object and returns it.
    public static AManager instance
    {
        get
        {
            if (s_Instance == null)
            {
                // FindObjectOfType() returns the first AManager object in the scene.
                s_Instance = FindObjectOfType(typeof(AManager)) as AManager;
            }
 
            // If it is still null, create a new instance
            if (s_Instance == null)
            {
                var obj = new GameObject("AManager");
                s_Instance = obj.AddComponent<AManager>();
            }
 
            return s_Instance;
        }
    }
 
 
    // Ensure that the instance is destroyed when the game is stopped in the editor.
    void OnApplicationQuit()
    {
        s_Instance = null;
    }
 
 
    // Add your own code here...
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox