【问题标题】:How to create a turn based manager in a board game using Photon in Unity with the dice?如何使用 Unity 中的 Photon 和骰子在棋盘游戏中创建回合制经理?
【发布时间】:2021-04-13 16:49:49
【问题描述】:

我遇到的问题是,当我将玩家 2 的骰子 SetActive 设置为 False 时,玩家 1 的骰子也会消失,因为 PhotonTargets 设置为 All 以使玩家令牌一起移动。下面是我尝试它的代码。我什至需要在这里编码这个逻辑还是应该在其他地方?提前致谢

public static void MoveSteps(string playerName, int numberOfSteps)
    {
        ScriptsPhotonView.RPC("MoveStepsRPC", PhotonTargets.All, playerName, numberOfSteps); 
    }

    [PunRPC]
    void MoveStepsRPC(string playerName, int numberOfSteps)
    {
        print("playerName:" + playerName);
        print("numberOfSteps:" + numberOfSteps);
        

        if (playerName == "Player1")
        {
            GameObject.Find(playerName).GetComponent<PlayerController>().Move(numberOfSteps);
            dice.SetActive(true);
        }
        
        else if (playerName == "Player2")
        {
           dice.SetActive(false);
        }
    }

【问题讨论】:

  • 您是否尝试过使用photonView.IsMine

标签: c# unity3d photon gkturnbasedmatch real-time-multiplayer


【解决方案1】:

我认为您甚至不必为其他玩家禁用骰子,只需让他们使用它的脚本即可。也许设置一个像“canMove”和if (!can move){diceScript.enabled = false;}这样的布尔值或者,您可以将骰子放在单独的层上,而轮到它的玩家没有相机忽略该层或其他东西。希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2011-06-26
    • 2020-03-19
    • 1970-01-01
    相关资源
    最近更新 更多