Network.Instantiate 实例化

static function Instantiate (prefab : Object, position : Vector3, rotation : Quaternion, group : int) : Object


Network instantiate a prefab.


The given prefab will be instanted on all clients in the game. Synchronization is automatically set up so there is no extra work involved. The position, rotation and network group number are given as parameters. Internally this is an RPC call so when Network.RemoveRPCs is called for the group number, the object will be removed. Note that there must be something set to the playerPrefab in the Editor. You can read more about instantiations in the object reference Object.Instantiate.


using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Transform playerPrefab;
	void OnConnectedToServer() {
		Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
// 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);
Page last updated: 2011-4-4