Advertisement
bekovski

sg_u06_v2

Jun 18th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. using UnityEngine.UI;
  6. using UnityEngine.Networking;
  7.  
  8. public class ScoreManager : NetworkBehaviour {
  9.  
  10.     public static ScoreManager instance;
  11.  
  12.     public Text player1ScoreText;
  13.     public Text player2ScoreText;
  14.  
  15.     /*[SyncVar(hook = "OnPlayer1ScoreChange")]
  16.     [SyncVar(hook = "OnPlayer2ScoreChange")]*/
  17.  
  18.     [SyncVar(hook = "OnPlayer1ScoreChange")] int player1Score;
  19.     [SyncVar(hook = "OnPlayer2ScoreChange")] int player2Score;
  20.  
  21.     void Awake() {
  22.         instance = this;
  23.     }
  24.  
  25.     // Use this for initialization
  26.     void Start () {
  27.         player1Score = 0;
  28.         player2Score = 0;
  29.     }
  30.  
  31.     [ClientRpc]
  32.     void RpcScoreDisplayUpdate() {
  33.         player1ScoreText.text = player1Score.ToString ();
  34.         player2ScoreText.text = player2Score.ToString ();
  35.        
  36.     }
  37.  
  38.     [Command]
  39.     void CmdScoreDisplayUpdate() {
  40.         /*player1ScoreText.text = player1Score.ToString ();
  41.         player2ScoreText.text = player2Score.ToString ();*/
  42.         RpcScoreDisplayUpdate ();
  43.     }
  44.  
  45.     public void IncPlayer1Score() {
  46.         player1Score++;
  47.         CmdScoreDisplayUpdate ();
  48.     }
  49.  
  50.     public void IncPlayer2Score() {
  51.         player2Score++;
  52.         CmdScoreDisplayUpdate ();
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement