PlayerScore.cs 799 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. namespace Mirror.Examples.MultipleAdditiveScenes
  3. {
  4. public class PlayerScore : NetworkBehaviour
  5. {
  6. [SyncVar]
  7. public int playerNumber;
  8. [SyncVar]
  9. public int scoreIndex;
  10. [SyncVar]
  11. public int matchIndex;
  12. [SyncVar]
  13. public uint score;
  14. public int clientMatchIndex = -1;
  15. void OnGUI()
  16. {
  17. if (!isServerOnly && !isLocalPlayer && clientMatchIndex < 0)
  18. clientMatchIndex = NetworkClient.connection.identity.GetComponent<PlayerScore>().matchIndex;
  19. if (isLocalPlayer || matchIndex == clientMatchIndex)
  20. GUI.Box(new Rect(10f + (scoreIndex * 110), 10f, 100f, 25f), $"P{playerNumber}: {score}");
  21. }
  22. }
  23. }