Multiplayer [TeamScript] - Client doesn't sync from Server.
This script is attached to Player Object and working on assign Team to each player.
[The Current Issues]
However, I can only successfully assign team to every player on the Server side. On the client side, when I join the Game I can sync and get assign to team only work for my own' player object. Other player did not manage to get sync.
In other words, only clients don't see the team assignation. So if anyone can tell me the solution of what is wrong and what is right, I will be appreciate it!
Networking Engine & NetworkBehaviour are in the script. Below is my script:
[SyncVar]
private int TeamNo;
void Start()
{
int IndexRandomise = Random.Range(1,3);
TeamNo = IndexRandomise;
if(!isLocalPlayer)
{
}
else
{
Cmd_VisualRecognition(TeamNo);
}
}
[Command]
public void Cmd_VisualRecognition(int _TeamNo)
{
RpcVisualised(_TeamNo);
}
[ClientRpc]
void RpcVisualised(int _TeamNo)
{
if(isServer)
{
if (_TeamNo == 1)
{
this.transform.GetComponent<SpriteRenderer>().color = Color.blue;
}
else
{
this.transform.GetComponent<SpriteRenderer>().color = Color.red;
}
}
else
{
if (_TeamNo == 1)
{
this.transform.GetComponent<SpriteRenderer>().color = Color.blue;
}
else
{
this.transform.GetComponent<SpriteRenderer>().color = Color.red;
}
}
}
I've been trying different method all seemss the same result. Client that just joined the game doesn't get update from other player's $$anonymous$$m assigning.
[SyncVar(hook = "AssignTeam")] private int TeamNo;
void Start()
{
int IndexRandomise = Random.Range(1,3);
TeamNo = IndexRandomise;
if(!isLocalPlayer)
{
}
else
{
AssignTeam(TeamNo);
}
}
}
public void AssignTeam(int _TeamNo)
{
if(!isLocalPlayer)
return;
if (_TeamNo == 1)
{
this.transform.GetComponent<SpriteRenderer>().color = Color.blue;
}
else
{
this.transform.GetComponent<SpriteRenderer>().color = Color.red;
}
CmdTransmitToAll(_TeamNo);
}
[Command]
void CmdTransmitToAll(int _TeamNo)
{
if (_TeamNo == 1)
{
this.transform.GetComponent<SpriteRenderer>().color = Color.blue;
}
else
{
this.transform.GetComponent<SpriteRenderer>().color = Color.red;
}
}
Your answer
Follow this Question
Related Questions
Simple Question: Is the Unity 5.4+ "NetworkLobbyManager" bugged? 0 Answers
Using syncVar in networkManager 1 Answer
Unity Network Spawning Prefabs 0 Answers
Unity Photon Player Instantiation 1 Answer
Unity Networking: Loading Screen 0 Answers