I set autoCreatePlayer to false and I run two Functions on two Gui Buttons. Each connection gets 2 options for a test.
public class SpawnPlayer : NetworkBehaviour {
public GameObject[] playerSelected;
[Command]
public void CmdSyncPlayerSelection(int player)
{
NetworkManager.singleton.playerPrefab = playerSelected[player];
}
}
//Separate Script, just the function.
public void SpawnAPlayer()
{
playerSelectPanel.gameObject.SetActive(false);
ClientScene.AddPlayer(0);
}
I tried adding a [SyncVar] attribute to ‘public GameObject[ ] playerSelected;’, but the console told me to try SyncLists. I’ll take time to figure this lead out, but am I on the right track? This code didn’t work without the [SyncVar] either.
What’s happening is that I can choose the player on the Host, but the remote client’s player when spawned is identical to the Host’s (no matter what gui button I choose). So I ran a build as host and used the editor as a remote client. After selecting the opposite player on the remote client, it displayed the correct gameObject in the playerPrefab variable in the NetworkManager. Yet it still spawns the wrong gameObject. Very frustrating.
I’m running this script on the PlayerSelectionPanel, perhaps I can spawn an empty in case I absolutely need a player object to run [command]. Both gameObjects are inside the Spawnable Objects list in the Net Manager.