Question by
Remonell · May 15, 2017 at 04:11 PM ·
networkingtextuser interfacesynchronization
UI Text synchronize with UNET
HI there,
I have a game with 2 teams. Every player of every team should see the teamscore on his screen. Every player sees 0:0 as that is the initial score. But when 1 team scores only the host sees 1:0. On all the other players its still 0:0.
Can you help me with that? Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class GameManager : NetworkBehaviour {
[SyncVar(hook = "updateRedScoreText")]
public int scoreRed;
[SyncVar(hook = "updateBlueScoreText")]
private int scoreBlue;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void raiseScore(int team) {
if (team == 0) {
scoreBlue++;
} else if(team == 1){
scoreRed++;
}
Debug.Log("Score Blau: " + scoreBlue);
Debug.Log("Score Rot: " + scoreRed);
updateRedScoreText(scoreRed);
updateBlueScoreText(scoreBlue);
}
public void updateRedScoreText(int r) {
Text scoreRotText = GameObject.Find("scoreRotUI").GetComponent<Text>();
scoreRotText.text = r.ToString();
}
public void updateBlueScoreText(int b) {
Text scoreBlauText = GameObject.Find("scoreBlauUI").GetComponent<Text>();
scoreBlauText.text = b.ToString();
}
}
The UI Texts have the network identity as a component with local player authority. http://prntscr.com/f84iv3
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612122047im_/https://answers.unity.com/themes/thub/images/avi.jpg)