问题描述
我正在尝试制作一个智能可用的对象系统。
当玩家接近其中一个可用物品时,他将能够按下按钮并使用该特定物品。除了 use 命令执行外,一切正常;
using UnityEngine;
using Mirror;
public class Usable : NetworkBehavIoUr
{
public void Use(GameObject[] allUsables,Player CurrentClient,GameObject[] vents = null)
{
if (CurrentClient.isLocalPlayer)
{
//this.GetComponent<NetworkIdentity>().AssignClientAuthority(CurrentClient.GetComponent<NetworkIdentity>().connectionToClient);
switch (this.name)
{
case string name when name.Contains("EmergencyButton"):
Debug.Log("Reached Log Point");
CmdEmergencyButton();
break;
default:
Debug.LogError("Not possible!");
break;
}
//this.GetComponent<NetworkIdentity>().RemoveClientAuthority();
}
}
[Command]
private void CmdEmergencyButton()
{
RpcEmergency();
}
[ClientRpc]
private void RpcEmergency()
{
//Activates emergency button effect
GameObject.Find("EmergencyButton").transform.GetChild(0).gameObject.SetActive(true);
}
}
[Client]
void ActivateUse()
{
if(isLocalPlayer)
{
Debug.Log("Client using");
//currUsables has all the nearby usable objects
GameObject currentToUse = GameObject.Find(currUsables[0].name);
//Using that object.
currentToUse.GetComponent<Usable>().Use(allUsables,this,allVents);
}
}
来自玩家对象。
调用 CmdEmergencyButton() 时,除了控制台中的此警告外,没有任何反应;
Click to see warning
Trying to send command for object without authority. Usable.CmdEmergencyButton
UnityEngine.Logger:Log(LogType,Object)
我已经尝试授权客户端使用来自这个对象的命令(使用函数中的注释),但仍然没有。
知道为什么它不起作用吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)