Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.49 KB | None | 0 0
  1. // Singleton class
  2. class Singleton
  3. {
  4.   private static Singleton instance;
  5.   public static Singleton Instance
  6.   {
  7.     get
  8.     {
  9.       if (instance == null)
  10.         instance = new Singleton();
  11.       return instance;
  12.     }
  13.   }
  14.  
  15.   public GameObject Player { get; set; }
  16. }
  17.  
  18. // Attached to player
  19. class Player: MonoBehaviour
  20. {
  21.   Awake()
  22.   {
  23.     Singleton.Instance.Player = this.gameobject;
  24.   }
  25. }
  26.  
  27. // Now you can call Player from anywhere:
  28. var player = Singleton.Instance.Player;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement