TimeManager.cs 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. using System.Collections;
  3. public class TimeManager : MonoBehaviour
  4. {
  5. private static TimeManager _instance;
  6. public static TimeManager Instance
  7. {
  8. get
  9. {
  10. if (_instance == null)
  11. {
  12. _instance = FindObjectOfType(typeof(TimeManager)) as TimeManager;
  13. if (_instance == null)
  14. {
  15. 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));
  16. }
  17. }
  18. return _instance;
  19. }
  20. }
  21. void Awake()
  22. {
  23. if (_instance != null && _instance != this)
  24. {
  25. AVDebug.LogWarning(string.Format("{0} Instance already exists on another gameObject. Destroying this gameObject {1}", this.GetType().Name, gameObject.name));
  26. Destroy(gameObject);
  27. return;
  28. }
  29. _instance = this;
  30. DontDestroyOnLoad(gameObject);
  31. enabled = false;
  32. }
  33. }