【问题标题】:Getting 'NetworkServer' does not contain a definition for 'SpawnWithClientAuthority'获取“NetworkServer”不包含“SpawnWithClientAuthority”的定义
【发布时间】: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吗?

标签: unity3d mirror


【解决方案1】:

原因是 Mirror 已弃用 SpawnWithClientAuthority。 (https://mirror-networking.gitbook.io/docs/general/deprecations)

请改用 Spawn(GameObject obj, NetworkConnection ownerConnection)。

Screenshot from Mirror Website

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    相关资源
    最近更新 更多