Jisimni Josh
Jisimni Josh

Reputation: 29

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

The problem that I encountered is that when I set player 2's dice SetActive to False, it disappears for the player 1 as well since the PhotonTargets is set to All for the player tokens to move together. Below is the code how I attempted it. Do I even need to code this logic here or should it be somewhere else please ? Thanks in advance

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);
        }
    }

Upvotes: 0

Views: 914

Answers (1)

Justin Hawkins
Justin Hawkins

Reputation: 26

I don't think you even have to disable the dice for the other player, just the script for them to use it. Maybe set up a bool like,"canMove" and if (!can move){diceScript.enabled = false;} Alternatively, you could put the dice on a separate layer, and the player whose turn it isn't has their camera ignore that layer or something. Hope this helped.

Upvotes: 0

Related Questions