conn | Connection which is adding the player. |
player | Player object spawned for the player. |
playerControllerId | The player controller ID number as specified by client. |
bool True if player was added.
When a SYSTEM_ADD_PLAYER message handler has received a request from a player, the server should call this when he's created the player's object.
When a player is added for a connection, the client for that connection is made ready automatically. The player object is automatically spawned, so you do not need to call NetworkServer.Spawn for that object. This function is used for "adding" a player, not for "replacing" the player on a connection. If there is already a player on this playerControllerId for this connection, this will fail.
no example available in JavaScript
function Start() { NetworkServer.Instance.RegisterHandler(MsgType.SYSTEM_ADD_PLAYER, OnAddPlayerMessage); }
// On the client side function OnLevelWasLoaded() { Debug.Log("Finished loading " + Application.loadedLevelName); ClientManager.SetPlayerForConnection(myConnection, 0) }
// On the server side
function OnAddPlayerMessage(conn : NetworkConnection, reader : NetworkReader) {
GameObject thePlayer = (GameObject)Instantiate(singleton.player, pos, Quaternion.identity);
// This spawns the new player on all clients NetworkServer.Instance.AddPlayerForConnection(conn, thePlayer, 0); }