【问题标题】:Player's respawn dont work when synchronised同步时玩家的重生不起作用
【发布时间】:2021-11-19 08:06:09
【问题描述】:

我在播放器上使用 NetworkIdentity、Network Transform (Script) 和 Network Transform child 作为组件。但我发现如果我检查“同步位置”,我的重生脚本就不再工作了

private IEnumerator Respawn()
    {
        yield return new WaitForSeconds(GameManager.instance.matchSettings.respawnTimer);
        SetDefaults();
        Transform spawnPoint = NetworkManager.singleton.GetStartPosition();
        Debug.Log("Position avant : " + transform.position);
        transform.position = spawnPoint.position;
        transform.rotation = spawnPoint.rotation;

        Debug.Log("position après : " + spawnPoint.position);
    }

我的玩家停止移动,因为我在他死时停用了一些脚本(移动、射击脚本)

    void Die()
    {
        isDead = true;
        for (int i = 0; i < disableOnDeath.Length; i++)
        {
            disableOnDeath[i].enabled = false;
        }
        Collider col = GetComponent<Collider>();
        if(col != null)
        {
            col.enabled = false;
        }
        StartCoroutine(Respawn()); 
    }

要禁用的默认组件是:播放器的移动、他的摄像头、他的音频监听器和他的动作(暂时只拍摄)

void SetDefaults()
    {
        isDead = false;
        currentHealth = MaxHealth;

        for (int i = 0; i < disableOnDeath.Length; i++)
        {
            disableOnDeath[i].enabled = wasEnabledOnStart[i];
        }

        Collider col = GetComponent<Collider>();
        if (col != null)
        {
            col.enabled = true;
        }
    }

唯一不起作用的是玩家在我的出生点重生。当玩家死亡时,他不能射击也不能移动。但它不会重生。

【问题讨论】:

    标签: c# unity3d mirror


    【解决方案1】:

    [英文/法文]

    要求更多细节的评论会比这个回复更合适,但我还不能评论。因此,我假设缺少一些信息。

    1. 请使用SetDefault() 代码编辑您的帖子。
    2. 我假设SetDefaults() 方法的作用与Die() 正好相反。检查您是否没有遗漏任何内容(disableOnDeath[*].enabled = true,恢复对撞机等)。

    法国:

    Un commentaire pour plus d'informations serait plus approprié qu'une réponse directe mais je ne peux pas encore en faire。 Du coup, je fait des supposition sur certains détails。

    1. S'il-te-plais, peux-tu étider ton post pour ajouter le code de SetDefault()?
    2. 我猜是SetDefault() fait l'inverse de Die()。 Vérifie bien si c'est le cas(réactive les item dans disableOnDeath[], réactive les colliders 等)。 Autrement, ils ne sont pas réactivés。

    【讨论】:

    • 我已经完成了你想要的修改
    • 我刚刚意识到我可能弄错了你的问题。在您的帖子末尾,您写道:When the player dies he cant shoot and cant move. But it doesnt respawn. 你的意思是can shoot and move but cannot respawn 吗?我一开始以为只是拍摄和移动不起作用,我弄错了吗?另外,你在哪里声明disableOnDeathwasEnableOnStart 的元素?如果它们相同,我建议您只使用一个数组。
    • 我在引擎上声明了元素。正如我所说的,它的玩家、他的摄像头、他的音频听众和他的动作的运动(暂时只拍摄)。澄清一下,我的问题是当我杀死一个玩家时,他不能再移动并射击 3 秒(这在我的重生脚本中很正常)但被杀死的玩家不会在另一个重生点重生。我可以看到被杀死的玩家在重生点上重生一两帧,但它会立即回到被杀死的位置。如果您需要更多说明,请告诉我
    • 好的。我只是检查了镜子,我以前从未使用过它,所以我可能不是回答你问题的合适人选:/ 尽管如此,由于这是一个同步问题,可能是因为播放器没有正确的“移动”自己。 NetworkTransform.ClientAuthority 是否被选中?据我了解,如果不是服务器应该是控制位置的人。如果您希望客户端控制播放器,请取消选中它。另外,您的播放器上的NetworkTransformChild 所针对的转换是什么?
    • 检查客户端权限,以便玩家可以控制自己。我的NetworkTransformChild 中没有看到转换参数
    猜你喜欢
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多