【发布时间】:2019-11-21 01:39:17
【问题描述】:
我正在使用 UNET 开发多人游戏。每次我通过在编辑器中玩游戏来主持比赛时,加入的每个玩家都被视为服务器并且游戏按预期运行。如果我使用内置游戏(不使用 Unity 编辑器)主持比赛,加入的每个玩家都被视为客户端,并且他们都在相同的网络生成位置生成,并且每次我的敌人生成器尝试实例化敌人时预制件,我收到一条错误消息。
我真的不明白发生了什么。
我尝试过在线学习其他教程,但没有任何帮助。 我将在下面列出代码和错误。
//为了检查播放器是客户端还是服务器,我在//播放器设置脚本中编写了这段代码:
"if (isServer)
Debug.Log("server");
else
Debug.Log("Client");"
//此代码用于播放器脚本中,以在被敌人子弹击中时受到伤害
private void OnTriggerEnter2D(Collider2D hitInfo)
{
if (hitInfo.tag == "Enemy" || hitInfo.tag == "EnemyBullet")
{
RpcTakeDamage(10, "hit by enemy");
}
}
[ClientRpc]
public void RpcTakeDamage(int _amount, string _sourceID)
{
if (!isHit)
{
StartCoroutine("HurtColor");
currentHealth -= _amount;
Debug.Log(transform.name + " now has " + currentHealth + " health ");
if (currentHealth <= 0)
{
Die(_sourceID);
}
}
}
//到目前为止的Die函数只是销毁玩家游戏对象
//当我加入内置游戏托管的游戏时会出现这些错误
"Network configuration mismatch detected. The number of networked scripts on the client does not match the number of networked scripts on the server. This could be caused by lazy loading of scripts on the client. This warning can be disabled by the checkbox in NetworkManager Script CRC Check."
"CRC Local Dump PlayerSetup : 0"
"Trying to send command for object without authority."
//每当我的敌人生成器尝试生成一个敌人时,当 //game 由构建的游戏托管并且每个玩家都被视为客户端时,就会发生这种情况 //敌人预制件仍然会按预期生成并移动
"SpawnObject for EnemyUpRight(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server."
//当敌人的子弹击中玩家时,会出现错误而不是受到伤害
"RPC Function RpcTakeDamage called on client."
【问题讨论】:
标签: c# unity3d networking unity3d-unet