簡體   English   中英

如何使用 Unity 中的 Photon 和骰子在棋盤游戲中創建回合制經理?

[英]How to create a turn based manager in a board game using Photon in Unity with the dice?

我遇到的問題是,當我將玩家 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);
        }
    }

我認為您甚至不必為其他玩家禁用骰子,只需為他們使用它的腳本即可。 也許設置一個 bool 像 "canMove" 和if (.can move){diceScript;enabled = false;}或者,你可以把骰子放在一個單獨的層上,並且輪到它的玩家忽略他們的相機那個層什么的。 希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM