Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

NetworkServer.AddPlayerForConnection

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function AddPlayerForConnection(conn: Networking.NetworkConnection, player: GameObject, playerControllerId: short): bool;
public static bool AddPlayerForConnection(Networking.NetworkConnection conn, GameObject player, short playerControllerId);

Parámetros

conn Connection which is adding the player.
player Player object spawned for the player.
playerControllerId The player controller ID number as specified by client.

Valor de retorno

bool True if player was added.

Descripción

When an AddPlayer message handler has received a request from a player, the server calls this to associate the player object with the connection.

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.

#pragma strict
class MyServer extends MonoBehaviour {
	public var playerPrefab: GameObject;
	function Start() {
		NetworkServer.RegisterHandler(MsgType.AddPlayer, OnAddPlayerMessage);
	}
	function OnAddPlayerMessage(netMsg: NetworkMessage) {
		var thePlayer: GameObject = GameObjectInstantiate(playerPrefab, Vector3.Zero, Quaternion.identity);
		// This spawns the new player on all clients
		NetworkServer.AddPlayerForConnection(conn, thePlayer, 0);
	}
}
class MyServer : MonoBehaviour
{

public GameObject playerPrefab;

function Start() { NetworkServer.RegisterHandler(MsgType.AddPlayer, OnAddPlayerMessage); }

void OnAddPlayerMessage(NetworkMessage netMsg) {

GameObject thePlayer = (GameObject)Instantiate(playerPrefab, Vector3.Zero, Quaternion.identity);

// This spawns the new player on all clients NetworkServer.AddPlayerForConnection(conn, thePlayer, 0); } }