Network instantiate a prefab.
// Immediately instantiate new connected player's character // when successfully connected to the server. var playerPrefab : Transform; function OnConnectedToServer () { Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0); }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public Transform playerPrefab; void OnConnectedToServer() { Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0); } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): public playerPrefab as Transform def OnConnectedToServer() as void: Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0)
// Immediately destroy and remove RPC for network instantiated object // (script attached to prefab) function OnNetworkInstantiate(info: NetworkMessageInfo) { Debug.Log(networkView.viewID + " spawned"); if (Network.isServer) { Network.RemoveRPCs(networkView.viewID); Network.Destroy(gameObject); } }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { void OnNetworkInstantiate(NetworkMessageInfo info) { Debug.Log(networkView.viewID + " spawned"); if (Network.isServer) { Network.RemoveRPCs(networkView.viewID); Network.Destroy(gameObject); } } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): def OnNetworkInstantiate(info as NetworkMessageInfo) as void: Debug.Log((networkView.viewID + ' spawned')) if Network.isServer: Network.RemoveRPCs(networkView.viewID) Network.Destroy(gameObject)