- Home /
Making a GUI Label carrying a variable update when changed to all clients on network
So I have this script counting how many players are on each team, but I dont know the proper way of doing it. I figured I would wanna use arrays to hold track of how many players on each team and remove them when they disconnect, but I have no idea how.
Here's what I have atm.
using UnityEngine; using System.Collections;
public class SpawnManager : MonoBehaviour { public GameObject RunnerPlayer; public GameObject DeathPlayer;
public string CurTeam = "";
public GameObject SpawnPointRunner;
public GameObject SpawnPointDeath;
public int Runners = 0;
public int Death = 0;
public int MaxRunners;
public int MaxDeath ;
public float CenterW;
public float CenterH;
public bool NewRound = false;
// Use this for initialization
void Start () {
CurTeam = "";
CenterW = Screen.width / 2 - 150;
CenterH = Screen.height / 2 - 80;
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUI.Label (new Rect (0, 0, 75, 50), "Runners: " + Runners);
GUI.Label (new Rect (0, 20, 50, 50), "Death: " + Death);
GUI.Box (new Rect (CenterW, CenterH, 300, 160), "Select Team");
if (CurTeam == "") {
if (GUI.Button (new Rect (CenterW + 5, CenterH + 20, 290, 60), "Runner Team")) {
Network.Instantiate (RunnerPlayer, SpawnPointRunner.transform.position,transform.rotation, 0);
CurTeam = "Runner";
Runners++;
}
if (GUI.Button (new Rect (CenterW + 5, CenterH + 120, 290, 60), "Death Team")) {
Network.Instantiate (DeathPlayer, SpawnPointDeath.transform.position,transform.rotation, 0);
CurTeam = "Death";
Death++;
}
}
else
if (NewRound == true) {
Respawn();
}
}
void OnDisconnectedFromServer(NetworkDisconnection info) {
if (Network.isServer)
Debug.Log("Local server connection disconnected");
else
if (info == NetworkDisconnection.LostConnection)
Debug.Log("Lost connection to the server");
if(CurTeam == "Runner") {
Runners--;
}
if(CurTeam == "Death") {
Death--;
}
else
Debug.Log("Successfully diconnected from the server");
if(CurTeam == "Runner") {
Runners--;
}
if(CurTeam == "Death") {
Death--;
}
}
void Respawn() {
if(CurTeam == "Runner") {
Network.Instantiate (RunnerPlayer, SpawnPointRunner.transform.position,transform.rotation, 0);
NewRound = false;
}
if(CurTeam == "Death") {
Network.Instantiate (DeathPlayer, SpawnPointDeath.transform.position,transform.rotation, 0);
NewRound = false;
}
}
}
Thanks in advance
Comment