NetworkServer.SpawnWithClientAuthority

Switch to Manual
public static bool SpawnWithClientAuthority (GameObject obj, GameObject player);
public static bool SpawnWithClientAuthority (GameObject obj, Networking.NetworkConnection conn);
public static bool SpawnWithClientAuthority (GameObject obj, Networking.NetworkHash128 assetId, Networking.NetworkConnection conn);

Parameters

obj 要生成的对象。
player 要为其设置客户端权限的玩家对象。
assetId 要生成的对象的 assetId。用于自定义生成处理程序。
conn 要为其设置客户端权限的连接。

Returns

bool 如果已生成对象,则为 true。

Description

此方法会生成一个像 NetworkServer.Spawn() 一样的对象,同时将客户端权限分配到指定客户端。

这与为生成的对象调用 NetworkIdentity.AssignClientAuthority 一样。


using UnityEngine;
using UnityEngine.Networking;

class TestBehaviour : NetworkBehaviour { public GameObject otherPrefab; [Command] public void CmdSpawn() { GameObject go = (GameObject)Instantiate(otherPrefab, transform.position + new Vector3(0, 1, 0), Quaternion.identity); NetworkServer.SpawnWithClientAuthority(go, connectionToClient); } }