dimanche 28 juin 2020

How to add integers to an array and get a random number?

It's a favorite panel. You can select numbers (with button click) and than I would like to add this number to an array and than get a random number from this array.

public int runs;
public int randomNumber;
public int[] favorites = new int[75];

public void RandomButton()
{
    if (DataController.Instance.group == 3)
    {
            favorites[randomNumber] = UnityEngine.Random.Range(0, favorites.Length);
            Debug.Log(favorites[randomNumber]);
    }
}

public void b0()
{
    for (runs = 0; runs < favorites.Length; runs++)
    {
        favorites[runs] = 0;
    }
}

public void b1()
{
    for (runs = 0; runs < favorites.Length; runs++)
    {
        favorites[runs] = 1;
    }
}

I'm stuck , because I get random number between 0 - 75. I would like to have a random number from the "favorites" array after I click on the buttons.




Aucun commentaire:

Enregistrer un commentaire