0

I am doing a Ludo Game and currently I need to check which Player got the Highest Number from the Dice and the player which has the highest number goes on the starting position.

Currently I created this method to check which player got the highest number then the player which has the highest numbers runs the method MovePlayer().

Can someone advice me on how can i correctly get the number generated for Player and the number generated for Player 2 cause currently they are the same.

public void FirstTurn(){
    int player1Steps = GameObject.Find("Scripts").GetComponent<LevelManager>().randomNumberSteps;
    int player2Steps = GameObject.Find("Scripts").GetComponent<LevelManager>().randomNumberSteps;

    if(NetworkManager.MyGamePlayerId == "Player1" && player2Played == true)
    {
        if(player1Steps > player2Steps)
        {
            GenerateRandomNumber();
            HighestRollerPlayer1 = true;
        }

    } else if(NetworkManager.MyGamePlayerId == "Player2" && player1Played == true)
    {
        if(player2Steps > player1Steps)
        {
            GenerateRandomNumber();
            HighestRollerPlayer2 = true;
        }
    }
}

I am using the Photon Cloud Service since this is a multiplayer Game Thanks

lambodar
  • 3,495
  • 5
  • 34
  • 58
Mark
  • 15
  • 6

1 Answers1

1

I recommend you to read this: Generate a Random Number that could Step in C#. you can't use the class that you are using I would get the number like this:

Random rnd = new Random();
int dice1  = rnd.Next(1, 7);
int dice2 = rnd.Next(1,7);

in case that we are talking about a regular dice (there are special dices with more or less carats).

It is well explained here: How do I generate a random int number?

Iria
  • 433
  • 1
  • 8
  • 20
  • The question is about Unity, and Unity has his own library with static methods for random numbers, you can do `int dice1 = Random.Range(1,7);` – Windgate Dec 19 '19 at 09:26