Call a RPC function on all connected peers.
var cubePrefab : Transform; function OnGUI () { if (GUILayout.Button("SpawnBox")) { var viewID : NetworkViewID= Network.AllocateViewID(); networkView.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 Example : MonoBehaviour { public Transform cubePrefab; void OnGUI() { if (GUILayout.Button("SpawnBox")) { NetworkViewID viewID = Network.AllocateViewID(); networkView.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; } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): public cubePrefab as Transform def OnGUI() as void: if GUILayout.Button('SpawnBox'): viewID as NetworkViewID = Network.AllocateViewID() networkView.RPC('SpawnBox', RPCMode.AllBuffered, viewID, transform.position) [RPC] def SpawnBox(viewID as NetworkViewID, location as Vector3) as void: clone as Transform clone = ((Instantiate(cubePrefab, location, Quaternion.identity) as Transform) as Transform) nView as NetworkView nView = clone.GetComponent[of NetworkView]() nView.viewID = viewID
Call a RPC function on a specific player.