Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- public class ScoreManager : NetworkBehaviour {
- public static ScoreManager instance;
- public Text player1ScoreText;
- public Text player2ScoreText;
- /*[SyncVar(hook = "OnPlayer1ScoreChange")]
- [SyncVar(hook = "OnPlayer2ScoreChange")]*/
- [SyncVar(hook = "OnPlayer1ScoreChange")] int player1Score;
- [SyncVar(hook = "OnPlayer2ScoreChange")] int player2Score;
- void Awake() {
- instance = this;
- }
- // Use this for initialization
- void Start () {
- player1Score = 0;
- player2Score = 0;
- }
- [ClientRpc]
- void RpcScoreDisplayUpdate() {
- player1ScoreText.text = player1Score.ToString ();
- player2ScoreText.text = player2Score.ToString ();
- }
- [Command]
- void CmdScoreDisplayUpdate() {
- /*player1ScoreText.text = player1Score.ToString ();
- player2ScoreText.text = player2Score.ToString ();*/
- RpcScoreDisplayUpdate ();
- }
- public void IncPlayer1Score() {
- player1Score++;
- CmdScoreDisplayUpdate ();
- }
- public void IncPlayer2Score() {
- player2Score++;
- CmdScoreDisplayUpdate ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement