Question by
coolnether123 · Apr 10, 2017 at 02:07 PM ·
c#arrayrandom.rangedata storage
Creating an Array that can be accessed by a Random.Range c#
I'm wanting to create a way of grouping up voids that are named and allowing a random.range or something of that sort to go too one of those voids. I have been trying for days to figure this out but i can't find a good source to store the data and a way to have the random.range to go too a random void in the data. Please explain how
void born () {
text.text = "Welcome to the world!";
if //if stuff
else if // other stuff}
Comment
By void you refer to a $$anonymous$$ethod call I suppose?
colors[0]=Color.black;
colors[1]=Color.red;
colors[2]=Color.blue;
colors[3]=Color.red;
colors[4]=Color.yellow;
colors[5]=Color.magenta;
cubeRenderer.material.color=colors[UnityEngine.Random.Range(0,colors.Length)];
Answer by Cuttlas-U · Apr 10, 2017 at 04:58 PM
hi; I did some thing like this with creating an array of int and base on the number call the right void ;
switch ( array[x] )
{
case 0 : // calling void 0 ; break;
case 1: // calling void 1 ; break;
case 2: // calling void 2; break;
.
.
.
}