Network.Instantiate 实例化

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

Description描述

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.

给定的预设将在所有的客户端上实例化。同步被自动设置,因此没有额外的工作要做。位置、旋转和网络组数值作为给定的参数。这是一个RPC调用,因此,当为该组数Network.RemoveRPCs被调用,这个物体将被移除。注意在编辑器中必须设置playerPrefab,在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);
}
最后修改:2011年4月4日 Monday 15:58

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。