Question by
ewoudwerf · Mar 20, 2016 at 12:11 PM ·
c#networkingserverclientclient-server
non-player object can't execute's "[Command]"'s attributes
i am making a team sorting system, but only the Host* (*aka Master, aka Server) can join a team, the Client can't join a team, when clicking on a button the script is attached to an empty gameobject (not the player object)
here is the whole script:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;
public class TeamSorting : NetworkBehaviour {
public Text BluePlayer_0;
public Text BluePlayer_1;
public Text BluePlayer_2;
public Text BluePlayer_3;
public Text RedPlayer_0;
public Text RedPlayer_1;
public Text RedPlayer_2;
public Text RedPlayer_3;
public GameObject StartButton;
public GameObject TeamMenu;
public GameObject HUD;
bool RedReady = false;
bool BlueReady = false;
[SyncVar]
public string UserName;
public GameObject LocalPlayer;
public GameObject[] Players;
public Transform[] BlueRespawns;
public Transform[] RedRespawns;
public bool IsBlue = false;
public bool IsRed = false;
[SyncVar]
public bool BlueRespawn0IsTaken = false;
[SyncVar]
public bool BlueRespawn1IsTaken = false;
[SyncVar]
public bool BlueRespawn2IsTaken = false;
[SyncVar]
public bool BlueRespawn3IsTaken = false;
[SyncVar]
public bool RedRespawn0IsTaken = false;
[SyncVar]
public bool RedRespawn1IsTaken = false;
[SyncVar]
public bool RedRespawn2IsTaken = false;
[SyncVar]
public bool RedRespawn3IsTaken = false;
void Start ()
{
HUD.SetActive (false);
TeamMenu.SetActive (true);
BluePlayer_0.text = "";
BluePlayer_1.text = "";
BluePlayer_2.text = "";
BluePlayer_3.text = "";
RedPlayer_0.text = "";
RedPlayer_1.text = "";
RedPlayer_2.text = "";
RedPlayer_3.text = "";
//StartButton.SetActive (false);
StartButton.transform.localScale = new Vector3 (0F, 0F, 0F);
if ( PlayerPrefs.GetString ("UserName") != "")
{
UserName = PlayerPrefs.GetString ("UserName");
}
else
{
UserName = "Jeff";
}
}
void Update ()
{
if (CrossPlatformInputManager.GetButtonDown ("StartGame"))
{
Players = GameObject.FindGameObjectsWithTag ("BluePlayer");
CmdStartGame ();
if (Players [0].GetComponent<SetupLocalPlayer> ().RandomID == PlayerPrefs.GetString ("LocalPlayerID") && Players [0].GetComponent<SetupLocalPlayer>() != null && Players[0] != null)
{
if (IsBlue == true)
{
if (BlueRespawn0IsTaken == false)
{
BlueRespawn0IsTaken = true;
Players [0].transform.position = BlueRespawns [0].transform.position;
Players [0].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn1IsTaken == false)
{
BlueRespawn1IsTaken = true;
Players [0].transform.position = BlueRespawns [1].transform.position;
Players [0].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn2IsTaken == false)
{
BlueRespawn2IsTaken = true;
Players[0].transform.position = BlueRespawns [2].transform.position;
Players[0].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn3IsTaken == false)
{
BlueRespawn3IsTaken = true;
Players[0].transform.position = BlueRespawns [3].transform.position;
Players[0].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
}
}
}
}
if (IsRed == true)
{
if (RedRespawn0IsTaken == false)
{
RedRespawn0IsTaken = true;
Players[0].transform.position = RedRespawns [0].transform.position;
Players[0].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn1IsTaken == false)
{
RedRespawn1IsTaken = true;
Players[0].transform.position = RedRespawns [1].transform.position;
Players[0].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn2IsTaken == false)
{
RedRespawn2IsTaken = true;
Players[0].transform.position = RedRespawns [2].transform.position;
Players[0].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn3IsTaken == false)
{
RedRespawn3IsTaken = true;
Players[0].transform.position = RedRespawns [3].transform.position;
Players[0].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
}
}
}
}
print ("Player0 is the localplayer");
}
if (Players [1].GetComponent<SetupLocalPlayer> ().RandomID == PlayerPrefs.GetString ("LocalPlayerID") && Players [1].GetComponent<SetupLocalPlayer>() != null && Players[1] != null)
{
if (IsBlue == true)
{
if (BlueRespawn0IsTaken == false)
{
BlueRespawn0IsTaken = true;
Players [1].transform.position = BlueRespawns [0].transform.position;
Players [1].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn1IsTaken == false)
{
BlueRespawn1IsTaken = true;
Players [1].transform.position = BlueRespawns [1].transform.position;
Players [1].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn2IsTaken == false)
{
BlueRespawn2IsTaken = true;
Players[1].transform.position = BlueRespawns [2].transform.position;
Players[1].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn3IsTaken == false)
{
BlueRespawn3IsTaken = true;
Players[1].transform.position = BlueRespawns [3].transform.position;
Players[1].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
}
}
}
}
if (IsRed == true)
{
if (RedRespawn0IsTaken == false)
{
RedRespawn0IsTaken = true;
Players[1].transform.position = RedRespawns [0].transform.position;
Players[1].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn1IsTaken == false)
{
RedRespawn1IsTaken = true;
Players[1].transform.position = RedRespawns [1].transform.position;
Players[1].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn2IsTaken == false)
{
RedRespawn2IsTaken = true;
Players[1].transform.position = RedRespawns [2].transform.position;
Players[1].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn3IsTaken == false)
{
RedRespawn3IsTaken = true;
Players[1].transform.position = RedRespawns [3].transform.position;
Players[1].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
}
}
}
}
print ("Player1 is the localplayer");
}
if (Players [2].GetComponent<SetupLocalPlayer> ().RandomID == PlayerPrefs.GetString ("LocalPlayerID") && Players [2].GetComponent<SetupLocalPlayer>() != null && Players[2] != null)
{
if (IsBlue == true)
{
if (BlueRespawn0IsTaken == false)
{
BlueRespawn0IsTaken = true;
Players [2].transform.position = BlueRespawns [0].transform.position;
Players [2].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn1IsTaken == false)
{
BlueRespawn1IsTaken = true;
Players [2].transform.position = BlueRespawns [1].transform.position;
Players [2].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn2IsTaken == false)
{
BlueRespawn2IsTaken = true;
Players[2].transform.position = BlueRespawns [2].transform.position;
Players[2].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn3IsTaken == false)
{
BlueRespawn3IsTaken = true;
Players[2].transform.position = BlueRespawns [3].transform.position;
Players[2].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
}
}
}
}
if (IsRed == true)
{
if (RedRespawn0IsTaken == false)
{
RedRespawn0IsTaken = true;
Players[2].transform.position = RedRespawns [0].transform.position;
Players[2].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn1IsTaken == false)
{
RedRespawn1IsTaken = true;
Players[2].transform.position = RedRespawns [1].transform.position;
Players[2].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn2IsTaken == false)
{
RedRespawn2IsTaken = true;
Players[2].transform.position = RedRespawns [2].transform.position;
Players[2].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn3IsTaken == false)
{
RedRespawn3IsTaken = true;
Players[2].transform.position = RedRespawns [3].transform.position;
Players[2].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
}
}
}
}
print ("Player2 is the localplayer");
}
if (Players [3].GetComponent<SetupLocalPlayer> ().RandomID == PlayerPrefs.GetString ("LocalPlayerID") && Players [3].GetComponent<SetupLocalPlayer>() != null && Players[3] != null)
{
if (IsBlue == true)
{
if (BlueRespawn0IsTaken == false)
{
BlueRespawn0IsTaken = true;
Players [3].transform.position = BlueRespawns [0].transform.position;
Players [3].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn1IsTaken == false)
{
BlueRespawn1IsTaken = true;
Players [3].transform.position = BlueRespawns [1].transform.position;
Players [3].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn2IsTaken == false)
{
BlueRespawn2IsTaken = true;
Players[3].transform.position = BlueRespawns [2].transform.position;
Players[3].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn3IsTaken == false)
{
BlueRespawn3IsTaken = true;
Players[3].transform.position = BlueRespawns [3].transform.position;
Players[3].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
}
}
}
}
if (IsRed == true)
{
if (RedRespawn0IsTaken == false)
{
RedRespawn0IsTaken = true;
Players[3].transform.position = RedRespawns [0].transform.position;
Players[3].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn1IsTaken == false)
{
RedRespawn1IsTaken = true;
Players[3].transform.position = RedRespawns [1].transform.position;
Players[3].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn2IsTaken == false)
{
RedRespawn2IsTaken = true;
Players[3].transform.position = RedRespawns [2].transform.position;
Players[3].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn3IsTaken == false)
{
RedRespawn3IsTaken = true;
Players[3].transform.position = RedRespawns [3].transform.position;
Players[3].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
}
}
}
}
print ("Player3 is the localplayer");
}
if (Players [4].GetComponent<SetupLocalPlayer> ().RandomID == PlayerPrefs.GetString ("LocalPlayerID") && Players [4].GetComponent<SetupLocalPlayer>() != null && Players[4] != null)
{
if (IsBlue == true)
{
if (BlueRespawn0IsTaken == false)
{
BlueRespawn0IsTaken = true;
Players [4].transform.position = BlueRespawns [0].transform.position;
Players [4].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn1IsTaken == false)
{
BlueRespawn1IsTaken = true;
Players [4].transform.position = BlueRespawns [1].transform.position;
Players [4].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn2IsTaken == false)
{
BlueRespawn2IsTaken = true;
Players[4].transform.position = BlueRespawns [2].transform.position;
Players[4].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn3IsTaken == false)
{
BlueRespawn3IsTaken = true;
Players[4].transform.position = BlueRespawns [3].transform.position;
Players[4].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
}
}
}
}
if (IsRed == true)
{
if (RedRespawn0IsTaken == false)
{
RedRespawn0IsTaken = true;
Players[4].transform.position = RedRespawns [0].transform.position;
Players[4].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn1IsTaken == false)
{
RedRespawn1IsTaken = true;
Players[4].transform.position = RedRespawns [1].transform.position;
Players[4].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn2IsTaken == false)
{
RedRespawn2IsTaken = true;
Players[4].transform.position = RedRespawns [2].transform.position;
Players[4].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn3IsTaken == false)
{
RedRespawn3IsTaken = true;
Players[4].transform.position = RedRespawns [3].transform.position;
Players[4].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
}
}
}
}
print ("Player4 is the localplayer");
}
if (Players [5].GetComponent<SetupLocalPlayer> ().RandomID == PlayerPrefs.GetString ("LocalPlayerID") && Players [5].GetComponent<SetupLocalPlayer>() != null && Players[5] != null)
{
if (IsBlue == true)
{
if (BlueRespawn0IsTaken == false)
{
BlueRespawn0IsTaken = true;
Players [5].transform.position = BlueRespawns [0].transform.position;
Players [5].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn1IsTaken == false)
{
BlueRespawn1IsTaken = true;
Players [5].transform.position = BlueRespawns [1].transform.position;
Players [5].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn2IsTaken == false)
{
BlueRespawn2IsTaken = true;
Players[5].transform.position = BlueRespawns [2].transform.position;
Players[5].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn3IsTaken == false)
{
BlueRespawn3IsTaken = true;
Players[5].transform.position = BlueRespawns [3].transform.position;
Players[5].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
}
}
}
}
if (IsRed == true)
{
if (RedRespawn0IsTaken == false)
{
RedRespawn0IsTaken = true;
Players[5].transform.position = RedRespawns [0].transform.position;
Players[5].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn1IsTaken == false)
{
RedRespawn1IsTaken = true;
Players[5].transform.position = RedRespawns [1].transform.position;
Players[5].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn2IsTaken == false)
{
RedRespawn2IsTaken = true;
Players[5].transform.position = RedRespawns [2].transform.position;
Players[5].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn3IsTaken == false)
{
RedRespawn3IsTaken = true;
Players[5].transform.position = RedRespawns [3].transform.position;
Players[5].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
}
}
}
}
print ("Player5 is the localplayer");
}
if (Players [6].GetComponent<SetupLocalPlayer> ().RandomID == PlayerPrefs.GetString ("LocalPlayerID") && Players [6].GetComponent<SetupLocalPlayer>() != null && Players[6] != null)
{
if (IsBlue == true)
{
if (BlueRespawn0IsTaken == false)
{
BlueRespawn0IsTaken = true;
Players [6].transform.position = BlueRespawns [0].transform.position;
Players [6].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn1IsTaken == false)
{
BlueRespawn1IsTaken = true;
Players [6].transform.position = BlueRespawns [1].transform.position;
Players [6].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn2IsTaken == false)
{
BlueRespawn2IsTaken = true;
Players[6].transform.position = BlueRespawns [2].transform.position;
Players[6].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn3IsTaken == false)
{
BlueRespawn3IsTaken = true;
Players[6].transform.position = BlueRespawns [3].transform.position;
Players[6].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
}
}
}
}
if (IsRed == true)
{
if (RedRespawn0IsTaken == false)
{
RedRespawn0IsTaken = true;
Players[6].transform.position = RedRespawns [0].transform.position;
Players[6].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn1IsTaken == false)
{
RedRespawn1IsTaken = true;
Players[6].transform.position = RedRespawns [1].transform.position;
Players[6].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn2IsTaken == false)
{
RedRespawn2IsTaken = true;
Players[6].transform.position = RedRespawns [2].transform.position;
Players[6].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn3IsTaken == false)
{
RedRespawn3IsTaken = true;
Players[6].transform.position = RedRespawns [3].transform.position;
Players[6].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
}
}
}
}
print ("Player6 is the localplayer");
}
if (Players [7].GetComponent<SetupLocalPlayer> ().RandomID == PlayerPrefs.GetString ("LocalPlayerID") && Players [7].GetComponent<SetupLocalPlayer>() != null && Players[7] != null)
{
if (IsBlue == true)
{
if (BlueRespawn0IsTaken == false)
{
BlueRespawn0IsTaken = true;
Players [7].transform.position = BlueRespawns [0].transform.position;
Players [7].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn1IsTaken == false)
{
BlueRespawn1IsTaken = true;
Players [7].transform.position = BlueRespawns [1].transform.position;
Players [7].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn2IsTaken == false)
{
BlueRespawn2IsTaken = true;
Players[7].transform.position = BlueRespawns [2].transform.position;
Players[7].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
else
{
if (BlueRespawn3IsTaken == false)
{
BlueRespawn3IsTaken = true;
Players[7].transform.position = BlueRespawns [3].transform.position;
Players[7].transform.localEulerAngles = new Vector3 (0f, 90f, 0f);
}
}
}
}
}
if (IsRed == true)
{
if (RedRespawn0IsTaken == false)
{
RedRespawn0IsTaken = true;
Players[7].transform.position = RedRespawns [0].transform.position;
Players[7].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn1IsTaken == false)
{
RedRespawn1IsTaken = true;
Players[7].transform.position = RedRespawns [1].transform.position;
Players[7].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn2IsTaken == false)
{
RedRespawn2IsTaken = true;
Players[7].transform.position = RedRespawns [2].transform.position;
Players[7].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
else
{
if (RedRespawn3IsTaken == false)
{
RedRespawn3IsTaken = true;
Players[7].transform.position = RedRespawns [3].transform.position;
Players[7].transform.localEulerAngles = new Vector3 (0f, -90f, 0f);
}
}
}
}
}
print ("Player7 is the localplayer");
}
}
if (BluePlayer_0.text != "" || BluePlayer_1.text != "" || BluePlayer_2.text != "" || BluePlayer_3.text != "")
{
BlueReady = true;
}
else
{
BlueReady = false;
}
if (RedPlayer_0.text != "" || RedPlayer_1.text != "" || RedPlayer_2.text != "" || RedPlayer_3.text != "")
{
RedReady = true;
}
else
{
RedReady = false;
}
if (BlueReady == true && RedReady == true)
{
CmdStartButton (true);
//StartButton.SetActive (true);
}
else
{
CmdStartButton (false);
//StartButton.SetActive (false);
}
if (CrossPlatformInputManager.GetButtonDown ("JoinBlue"))
{
if (BluePlayer_0.text != "" + UserName && BluePlayer_1.text != "" + UserName && BluePlayer_2.text != "" + UserName && BluePlayer_3.text != "" + UserName)
{
IsRed = false;
IsBlue = true;
if (RedPlayer_0.text == "" + UserName)
{
CmdJoinTeam ("" + UserName, false, 0, true);
//RedPlayer_0.text = "";
}
if (RedPlayer_1.text == "" + UserName)
{
CmdJoinTeam ("" + UserName, false, 1, true);
//RedPlayer_1.text = "";
}
if (RedPlayer_2.text == "" + UserName)
{
CmdJoinTeam ("" + UserName, false, 2, true);
//RedPlayer_2.text = "";
}
if (RedPlayer_3.text == "" + UserName)
{
CmdJoinTeam ("" + UserName, false, 3, true);
//RedPlayer_3.text = "";
}
if (BluePlayer_0.text != "")
{
if (BluePlayer_1.text != "")
{
if (BluePlayer_2.text != "")
{
if (BluePlayer_3.text != "")
{
print ("Sorry were full!");
}
else
{
CmdJoinTeam ("" + UserName, true, 3, false);
//BluePlayer_3.text = "" + PlayerPrefs.GetString ("UserName");
}
}
else
{
CmdJoinTeam ("" + UserName, true, 2, false);
//BluePlayer_2.text = "" + PlayerPrefs.GetString ("UserName");
}
}
else
{
CmdJoinTeam ("" + UserName, true, 1, false);
//BluePlayer_1.text = "" + PlayerPrefs.GetString ("UserName");
}
}
else
{
CmdJoinTeam ("" + UserName, true, 0, false);
//BluePlayer_0.text = "" + PlayerPrefs.GetString ("UserName");
}
}
}
if (CrossPlatformInputManager.GetButtonDown ("JoinRed"))
{
if (RedPlayer_0.text != "" + UserName && RedPlayer_1.text != "" + UserName && RedPlayer_2.text != "" + UserName && RedPlayer_3.text != "" + UserName)
{
IsRed = true;
IsBlue = false;
if (BluePlayer_0.text == "" + UserName)
{
CmdJoinTeam ("" + UserName, true, 0, true);
//BluePlayer_0.text = "";
}
if (BluePlayer_1.text == "" + UserName)
{
CmdJoinTeam ("" + UserName, true, 1, true);
//BluePlayer_1.text = "";
}
if (BluePlayer_2.text == "" + UserName)
{
CmdJoinTeam ("" + UserName, true, 2, true);
//BluePlayer_2.text = "";
}
if (BluePlayer_3.text == "" + UserName)
{
CmdJoinTeam ("" + UserName, true, 3, true);
//BluePlayer_3.text = "";
}
if (RedPlayer_0.text != "")
{
if (RedPlayer_1.text != "")
{
if (RedPlayer_2.text != "")
{
if (RedPlayer_3.text != "")
{
print ("Sorry were full!");
}
else
{
CmdJoinTeam ("" + UserName, false, 3, false);
//RedPlayer_3.text = "" + PlayerPrefs.GetString ("UserName");
}
}
else
{
CmdJoinTeam ("" + UserName, false, 2, false);
//RedPlayer_2.text = "" + PlayerPrefs.GetString ("UserName");
}
}
else
{
CmdJoinTeam ("" + UserName, false, 1, false);
//RedPlayer_1.text = "" + PlayerPrefs.GetString ("UserName");
}
}
else
{
CmdJoinTeam ("" + UserName, false, 0, false);
//RedPlayer_0.text = "" + PlayerPrefs.GetString ("UserName");
}
}
}
}
[Command]
public void CmdJoinTeam(string username, bool IsTeamBlue, int WhichPlayer, bool Leave)
{
if (Leave == true)
{
RpcLeaveTeam (IsTeamBlue, WhichPlayer);
}
else
{
RpcJoinTeam (username, IsTeamBlue, WhichPlayer);
}
}
[ClientRpc]
public void RpcLeaveTeam(bool IsTeamBlue, int WhichPlayer)
{
if (IsTeamBlue == true)
{
if (WhichPlayer == 0)
{
BluePlayer_0.text = "";
}
if (WhichPlayer == 1)
{
BluePlayer_1.text = "";
}
if (WhichPlayer == 2)
{
BluePlayer_2.text = "";
}
if (WhichPlayer == 3)
{
BluePlayer_3.text = "";
}
}
else
{
if (WhichPlayer == 0)
{
RedPlayer_0.text = "";
}
if (WhichPlayer == 1)
{
RedPlayer_1.text = "";
}
if (WhichPlayer == 2)
{
RedPlayer_2.text = "";
}
if (WhichPlayer == 3)
{
RedPlayer_3.text = "";
}
}
}
[ClientRpc]
public void RpcJoinTeam(string username, bool IsTeamBlue, int WhichPlayer)
{
if (IsTeamBlue == true)
{
if (WhichPlayer == 0)
{
BluePlayer_0.text = "" + username;
}
if (WhichPlayer == 1)
{
BluePlayer_1.text = "" + username;
}
if (WhichPlayer == 2)
{
BluePlayer_2.text = "" + username;
}
if (WhichPlayer == 3)
{
BluePlayer_3.text = "" + username;
}
}
else
{
if (WhichPlayer == 0)
{
RedPlayer_0.text = "" + username;
}
if (WhichPlayer == 1)
{
RedPlayer_1.text = "" + username;
}
if (WhichPlayer == 2)
{
RedPlayer_2.text = "" + username;
}
if (WhichPlayer == 3)
{
RedPlayer_3.text = "" + username;
}
}
}
[Command]
public void CmdStartGame()
{
RpcStartGame ();
}
[ClientRpc]
public void RpcStartGame()
{
HUD.SetActive (true);
TeamMenu.SetActive (false);
}
[Command]
public void CmdStartButton(bool UseStartButton)
{
RpcStartButton (UseStartButton);
}
[ClientRpc]
public void RpcStartButton(bool UseStartButton)
{
if (UseStartButton == true)
{
if (StartButton.transform.localScale != new Vector3 (1, 1, 1))
{
StartButton.transform.localScale += new Vector3 (0.1F, 0.1F, 0.1F);
}
}
else
{
if (StartButton.transform.localScale != new Vector3 (0, 0, 0))
{
StartButton.transform.localScale -= new Vector3 (0.1F, 0.1F, 0.1F);
}
}
}
}
Comment