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.

Obsolete
NetworkView RPC functions are deprecated. Refer to the new Multiplayer Networking system.

NetworkView.RPC

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 function RPC(name: string, mode: RPCMode, params args: object[]): void;
public void RPC(string name, RPCMode mode, params object[] args);

Parámetros

Descripción

Call a RPC function on all connected peers.

The called function must have the @RPC tag set ([RPC] for C Sharp code). A NetworkView must be attached to the GameObject where the RPC function is being called. It doesn't matter if the NetworkView is being used for something else or just for the RPC function. If it is just for the RPC function, state synchronization should be turned off and the observed property can be set to none. RPC function names should be unique accross the scene, if two RPC functions in different scripts have the same name only one of them is called when RPC is invoked. RPC calls are always guaranteed to be executed in the same order as they are sent. The communication group set for the network view, with NetworkView.group, is used for the RPC call. To get information on the RPC itelf, you can add a NetworkMessageInfo parameter to the function declaration which will automatically contain the information. You don't need to change the way you call the RPC function when you do this. For more information see the RPC section of the manual. Valid RPC parameters are int, float, string, NetworkPlayer, NetworkViewID, Vector3 and Quaternion.

var cubePrefab : Transform;

var nView: NetworkView;

function Start() { nView = GetComponent.<NetworkView>(); }

function OnGUI () { if (GUILayout.Button("SpawnBox")) { var viewID : NetworkViewID= Network.AllocateViewID(); nView.RPC("SpawnBox", RPCMode.AllBuffered, viewID, transform.position); } }

@RPC function SpawnBox (viewID : NetworkViewID, location : Vector3) { // Instantate the prefab locally var clone : Transform; clone = Instantiate(cubePrefab, location, Quaternion.identity) as Transform; var nView : NetworkView; nView = clone.GetComponent.<NetworkView>(); nView.viewID = viewID; }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform cubePrefab; public NetworkView nView; void Start() { nView = GetComponent<NetworkView>(); } void OnGUI() { if (GUILayout.Button("SpawnBox")) { NetworkViewID viewID = Network.AllocateViewID(); nView.RPC("SpawnBox", RPCMode.AllBuffered, viewID, transform.position); } } [RPC] void SpawnBox(NetworkViewID viewID, Vector3 location) { Transform clone; clone = Instantiate(cubePrefab, location, Quaternion.identity) as Transform as Transform; NetworkView nView; nView = clone.GetComponent<NetworkView>(); nView.viewID = viewID; } }

public function RPC(name: string, target: NetworkPlayer, params args: object[]): void;
public void RPC(string name, NetworkPlayer target, params object[] args);

Parámetros

Descripción

Call a RPC function on a specific player.