Advertisement
Guest User

Untitled

a guest
Nov 11th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MiniGamesPlayer : NetworkBehaviour
  2. {
  3.     public MiniGamesLevel MiniGames => MiniGamesLevel.Instance;
  4.     public bool IsLocal => MiniGames.Players.Local == this;
  5.     public bool IsRemote => MiniGames.Players.Remote == this;
  6.  
  7.     protected override void OnNetworkPostSpawn()
  8.     {
  9.         base.OnNetworkPostSpawn();
  10.  
  11.         Debug.Log($"Mini Games Player {(NetworkObject.IsLocalPlayer ? "Local" : "Remote")} Spawned, Scene: {gameObject.scene}");
  12.  
  13.         //This is the line that will throw a null reference exception on any late-joining client as the "MiniGamesLevel.Instance" is still not set because the scene is not yet loaded
  14.         MiniGames.Players.Assign(this, NetworkObject.IsLocalPlayer);
  15.  
  16.         if (IsLocal)
  17.             name = $"Player [Local]";
  18.         else
  19.             name = $"Player [Remote]";
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement