【发布时间】:2021-07-05 00:38:08
【问题描述】:
我收到的“NetworkServer”不包含“SpawnWithClientAuthority”的定义,这是我的脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using Mirror;
using UnityEngine.EventSystems;
public class ShootHooks : NetworkBehaviour
{
[SerializeField]
private GameObject bulletPrefab;
private GameObject hook;
private void Awake()
{
if (!_camera) _camera = Camera.main;
}
private void Start()
{
this.CmdInstantiateHook();
//hook.SetActive(false);
//localPlayer = ClientScene.localPlayer.gameObject;
}
[Command]
void CmdInstantiateHook()
{
hook = Instantiate(bulletPrefab, this.transform.position, Quaternion.identity);
NetworkServer.SpawnWithClientAuthority(hook, connectionToClient);
NetworkIdentity hookID = hook.GetComponent<NetworkIdentity>();
this.ClientAttachHook(connectionToClient, hookID);
localPlayer = ClientScene.localPlayer.gameObject;
}
[Command]
void CmdSetActiveServerHook(NetworkIdentity objectID)
{
NetworkIdentity.spawned[objectID.netId].gameObject.SetActive(false);
}
[TargetRpc]
public void ClientAttachHook(NetworkConnection target, NetworkIdentity objectID)
{
hook = NetworkIdentity.spawned[objectID.netId].gameObject;
this.CmdSetActiveServerHook(objectID);
}
}
似乎是什么问题?
【问题讨论】:
-
您确定它指的是正确的类型吗?你还有其他类也叫
NetworkServer吗?