unity Photon OnTriggerStay2D 仅适用于主机

发布于 2025-01-11 16:52:49 字数 913 浏览 3 评论 0原文

我向我的游戏添加了额外福利(升级),但它们仅在您单独玩时才能正常工作,当多人在游戏中时,该功能将停止工作。 当玩家1(主机)进入触发器时,会出现一条弹出消息,显示按F购买等。但是当玩家2进入触发器时,该消息不会出现在他的屏幕上,而是出现在玩家1的屏幕上。

脚本:

    public void Update()
    {
        if(!view.IsMine) return;
        if(Input.GetKey(KeyCode.F))
        {
            isPressingF = true;
        }
        else
        {
            isPressingF = false;
        }
    }

    void OnTriggerStay2D (Collider2D collider)
    {
        if(!view.IsMine) return;
        
        if (!ownedHalet)
        {
            if(collider.gameObject.CompareTag("Player"))
            {
                juggConfirm.SetActive(true);
            
                if (isPressingF)
                {
                    if(PointSystem.Instance.points < 2500 )
                        return;
                    
                    BuyPerkHalet();
                }
            }
        }
    }
    ```

im adding perks (upgrades) to my game but they only work properly when you play alone, when multiple people are in the game, the functionality stops working.
when the player 1 (host) enters the trigger, a pop up message appears saying Press F to purchase etc etc.. but when player 2 enters the trigger, the message does not appear on his screen but on player 1's screen.

script:

    public void Update()
    {
        if(!view.IsMine) return;
        if(Input.GetKey(KeyCode.F))
        {
            isPressingF = true;
        }
        else
        {
            isPressingF = false;
        }
    }

    void OnTriggerStay2D (Collider2D collider)
    {
        if(!view.IsMine) return;
        
        if (!ownedHalet)
        {
            if(collider.gameObject.CompareTag("Player"))
            {
                juggConfirm.SetActive(true);
            
                if (isPressingF)
                {
                    if(PointSystem.Instance.points < 2500 )
                        return;
                    
                    BuyPerkHalet();
                }
            }
        }
    }
    ```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文