EgonMilanVotrubec

GameManager

Mar 27th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using JeffreyStephens.Weapons;
  2. using UnityEngine;
  3.  
  4. namespace JeffreyStephens.Game
  5. {
  6.     public class GameManager : MonoBehaviour
  7.     {
  8.         private static bool _applicationIsQuitting = false;
  9.         private static GameManager _Instance;
  10.         public static GameManager Instance
  11.         {
  12.             get
  13.             {
  14.                 if ( _applicationIsQuitting ) return null;
  15.  
  16.                 if ( _Instance == null )
  17.                 {
  18.                     GameObject instanceGameObject = GameObject.Find ( "GameManager" );
  19.  
  20.                     if ( instanceGameObject == null )
  21.                         instanceGameObject = new GameObject ( "GameManager", typeof ( GameManager ) );
  22.  
  23.                     if ( UnityEditor.EditorApplication.isPlaying )
  24.                         DontDestroyOnLoad ( instanceGameObject );
  25.  
  26.                     _Instance = instanceGameObject.GetComponent<GameManager> ( );
  27.                 }
  28.                 return _Instance;
  29.             }
  30.         }
  31.  
  32.  
  33.         [Header ( "GameManager Variables" )]
  34.         public WeaponManager WeaponManager;
  35.         // ------------------------------------------------------------------------------- Unity Functions
  36.         void Awake ( )
  37.         {
  38.             if ( GameManager.Instance != this )
  39.                 Destroy ( this );
  40.         }
  41.  
  42.  
  43.         void OnDestroy ( )
  44.         {
  45.             _applicationIsQuitting = true;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment