- Home /
Question by
Smurfj3 · May 27, 2017 at 02:04 PM ·
multiplayersynclobby
Unity Multiplayer SyncListStruct lobbymanager only showing on host
I seem not to understand syncliststruct, I am trying to update name tags but it only works on the host.
void Awake(){
DontDestroyOnLoad (gameObject);
}
//the playerlist class deriving from syncliststruct of type PlayerProperties
public class PlayerList : SyncListStruct<PlayerProperties> {
}
//Creating new playerlist
public PlayerList lst_Players = new PlayerList();
//Add a player to the list
[Command]
public void CmdAddPlayerToList(string name, GameObject playerobject){
lst_Players.Add (new PlayerProperties{ name = name, playerobject = playerobject});
RpcSetNameTags ();
}
//Make all clients update the name tags for all the players that are online
[ClientRpc]
private void RpcSetNameTags(){
foreach (PlayerProperties g in lst_Players) {
g.playerobject.transform.FindChild ("Canvas").transform.FindChild ("ui_PlayerName").GetComponent<Text> ().text = g.name;
}
}
//Removing client from list
[Command]
public void CmdRemovePlayerToList(PlayerProperties p){
lst_Players.Remove(p);
RpcSetNameTags ();
}
}
//the struct containing playername and the gameobject
public struct PlayerProperties{
public string name;
public GameObject playerobject;
}
Now in the LobbyManager I call the function CmdAddPlayerToList:
public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
{
//This hook allows you to apply state data from the lobby-player to the game-player
//just subclass "LobbyHook" and add it to the lobby object.
GameObject spawnpointblue = SpawnPoints [0];
GameObject spawnpointred = SpawnPoints [1];
gamePlayer.GetComponent<Player> ().PlayerName = lobbyPlayer.GetComponent<LobbyPlayer> ().playerName;
gamePlayer.GetComponent<Player> ().TeamColor = lobbyPlayer.GetComponent<LobbyPlayer> ().playerColor;
if (gamePlayer.GetComponent<Player> ().TeamColor == Color.blue) {
gamePlayer.transform.position = spawnpointblue.transform.position;
} else {
gamePlayer.transform.position = spawnpointred.transform.position;
}
Debug.Log ("Gameobject name : " + playermanager.gameObject.name);
playermanager.GetComponent<PlayerManager> ().CmdAddPlayerToList (lobbyPlayer.GetComponent<LobbyPlayer> ().playerName, gamePlayer);
return true;
}
Please help, I have no idea what I am doing wrong.
Comment
Your answer
Follow this Question
Related Questions
How to sync players in multiplayer game 1 Answer
Multiplayer Room? 2 Answers
Network animations 2 Answers
How to get all created rooms and join any one of them in PHOTON 2 Answers