Math - Remainders: Scalable Player Count C# Code

It seems to work:

//Private Variables
int playerSelection;

//Public Variables
public int[] playerCount = new int[4];
public bool turnFound = false;

// Start is called before the first frame update
void Start()
{
    //Intialize player selection value using remander from player count
    playerSelection = Random.Range(1, 100) % playerCount.Length;
    Debug.Log("playerSelection Value: " + playerSelection);

    //Determine player turn
    for(int i = 0; i < playerCount.Length; i++)
    {
        if (!turnFound)
        {
            if (playerSelection == i)
            {
                Debug.Log("It Is Curently Player " + ++i + "'s Turn");
            }

        } else i = playerCount.Length;
    }
}

I coded this by the seat of my pants and kinda was ina rush cause I really want to go play some Monster Hunter: Rise right now. Also I misspelt Remainder lol.

Edit:
Just thought of something to make it truly scalable; when Initializing the value for playerSelection change it to:

playerSelection = Random.Range(1, 10*playerCount.Length) % playerCount.Length;

This way you can have a player count greater than 100. Now Iā€™m gonna go get some hunts in.

1 Like

Haha I love how the want to play Monster Hunter made you work harder on completing this code. It looks code and how was Monster Hunter?

1 Like

Crafted full Bazelgeuse armor and got some pretty good charms now my charge blade really brings the big hurt.

Privacy & Terms