Hello , I’m new in development on unity and I have a project with a friend : to make a multiplayer game in 2D. But I have a problem. For the connection on my game I use a network manager so I create a new class who inherits Network Manager. I use a override method OnServerAddPlayer:
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
if (choix == 1)
{
GameObject player = (GameObject)GameObject.Instantiate(perso1, Vector3.zero, Quaternion.identity);
NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
NetworkServer.Spawn(player);
}
if (choix == 2)
{
GameObject player = (GameObject)GameObject.Instantiate(perso2, Vector3.zero, Quaternion.identity);
NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
NetworkServer.Spawn(player);
}
}
And i use too OnclientConnect :
public override void OnClientConnect(NetworkConnection conn)
{
ClientScene.Ready(conn);
ClientScene.AddPlayer(0);
}
I want that a client choose an prefab for be connected in the game but when I change my attribut “choix” the prefab of my client do not change. Please can you help me ?
I’m not very familiar with the networking framework in Unity, but from what I know, you might need to use the [Sync] attribute on the “choix” variable, to make it replicate to the clients.
Yes, but the problem is that it’s impossible to use Sync with the NetworkManager, He need the NetworkBehaviour but if i use this class I don’t redefine the OnserverAddPlayer.
Perhaps it’s possible to get the new connection, and then wait for the user to make a choice before spawning the player. So have the client connect, the client will see the choice screen, and then once they choose one (maybe with a coroutine that waits for (choix != 0), the server creates the player.