Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Singleton class
- class Singleton
- {
- private static Singleton instance;
- public static Singleton Instance
- {
- get
- {
- if (instance == null)
- instance = new Singleton();
- return instance;
- }
- }
- public GameObject Player { get; set; }
- }
- // Attached to player
- class Player: MonoBehaviour
- {
- Awake()
- {
- Singleton.Instance.Player = this.gameobject;
- }
- }
- // Now you can call Player from anywhere:
- var player = Singleton.Instance.Player;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement