I am currently making a bonus game for my slot machine, I have started a small snippet of code however, I do not know the best way to repeat a function untill the maximum number of numbers is generated.This is the bare basics so far. What is the best way to store the numbers and repeat till I have for example 25 Numbers?
//Generate Random Numbers
float generatenumbers(float min, float max)
{
int count = 0;
if (count != 15)
{
return Random.Range(min, max);
}
//store the numbers some how for the bonus game
float generated = generatenumbers(0f, 1000f);
string numbers = generated.ToString();
}
Ok, I have figured out how to do the random number and have setup this code. However, now my question is this how do I pull the random number from the public list?
using UnityEngine;
using Random = UnityEngine.Random;
using System.Collections;
using System;
using System.Collections.Generic;
public class BonusGame : MonoBehaviour
{
public List<Item> items;
void Start()
{
foreach (Item item in items)
item.SetRandomNumber();
}
}
[Serializable]
public class Item
{
public int randomNumber;
public void SetRandomNumber()
{
var Number = Random.Range(0, 5000);
}
}
using UnityEngine;
using Random = UnityEngine.Random;
using System.Collections;
using System;
using System.Collections.Generic;
public class RandomNumbers : MonoBehaviour
{
public int TotalNumberToGenerate = 25f; // you can override this in the inspector
piblic int[] GeneratedNumbers; // this is where they are stored for the bonus game
void Start()
{
generatenumbers(0, 1000);
}
//Generate Random Numbers
void generatenumbers(int min, int max)
{
GeneratedNumbers = new int[TotalNumberToGenerate]; //creates a fresh array
for(int i = 0; i < GeneratedNumbers.Length; i++)
{
GeneratedNumbers[i] = Random.Range(min, max);
Debug.Log("Generated " + GeneratedNumbers[i] + " in slot # " + i);
}
}
}