using UnityEngine; using System.Collections; public class TimeManager : MonoBehaviour { private static TimeManager _instance; public static TimeManager Instance { get { if (_instance == null) { _instance = FindObjectOfType(typeof(TimeManager)) as TimeManager; if (_instance == null) { AVDebug.LogError(string.Format("No gameObject with {0} component exists. Make sure to create a gameObject with {0} component", new System.Diagnostics.StackFrame().GetMethod().DeclaringType)); } } return _instance; } } void Awake() { if (_instance != null && _instance != this) { AVDebug.LogWarning(string.Format("{0} Instance already exists on another gameObject. Destroying this gameObject {1}", this.GetType().Name, gameObject.name)); Destroy(gameObject); return; } _instance = this; DontDestroyOnLoad(gameObject); enabled = false; } }