Spawn Player and give him control over his gameobject (SOLVED)

Hi,

i cant find in the api, how to spawn a player on the server side, and give the player the control over it.
I couldnt even find any possibility how to spawn a prefab on client side.

I tried NetworkServer.SpawnWithClientAuthority(playerGameObject, netMsg.conn); but this dont work.

First of all it seems that you are actually working with the HLAPI as the LLAPI is actually dealing with the Transport Layer of networking and the HLAPI encapsulates functionality built on top of the Transport Layer.

Secondly here is example code from a project of mine:

public GameObject SpawnPlayer(NetworkConnection conn) {
        GameObject player = (GameObject)Instantiate(playerPrefab);
        NetworkServer.AddPlayerForConnection(conn, player, 0);
}

Using AddPlayerForConnection for connection applies all the necessary settings that a player needs distinct from client owned objects. I believe this automatically spawns the player with client authority.

More information can be found on the topic of player instantiation in the networking documentation: http://docs.unity3d.com/ScriptReference/Networking.NetworkServer.AddPlayerForConnection.html

Regards,

Skerbey

Thanks Skerbey :slight_smile: