alexsosnovskiy

Example of static list

Feb 28th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. public class NetPlayer : Photon.MonoBehaviour
  2. {
  3.     public static readonly List<NetPlayer> Players = new List<NetPlayer>();
  4.  
  5.     public string Name { get; private set; }
  6.    
  7.     void Awake()
  8.     {
  9.         Players.Add(this);
  10.     }
  11.  
  12.     void OnDestroy()
  13.     {
  14.         Player.Remove(this);
  15.     }
  16. }
  17.  
  18. //in some scripts...
  19. class Fool
  20. {
  21.     void DoSomething()
  22.     {
  23.         var players = NetPlayer.Players;
  24.  
  25.         if(players[0].Name == "Admin"){
  26.             var go = players[0].gameObject;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment