I am trying to spawn 2 Players (host and client) at 2 different locations.
I have no idea how to do this because the player are automatically spawned by the network manager.
I have tried the following but failed horribly :(.
[Command]
void CmdSpawn()
{
var go = (GameObject)Instantiate(
gameObject,
transform.position + new Vector3(0,1,0),
Quaternion.identity);
NetworkServer.SpawnWithClientAuthority(go, connectionToClient);
}
How Can I Spawn Player object at a specific location?
NetworkManager already supports spawn positions.
Just add GameObjects where you want players to spawn and give them the NetworkStartPosition
component. NetworkManager will automatically detect the start positions and automatically use them according to your setting of "Player Spawn Method" either "Random" (one spawn position is randomly chosen for every player) or "Round Robin" (player #0 spawns at first position, player #1 at second and so forth).