I want to shuffle the numbers in my array
variable once, so I called my Shuffle
method from Start()
.
I then attempt access the sh
Currently, your array is declared within your Start()
function. This means it can only be accessed from within the Start()
function. If you want to be able to access the array from both Start()
and Update()
you need to increase its scope by declaring it globally. For example:
private System.Random _random = new System.Random();
float sec;
float timecount;
float starttime;
//declare array globally
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8};
void Start ()
{
starttime = Time.time;
Shuffle(array);
foreach (int value in array)
{
Debug.Log(value);
}
}
void Update ()
{
//now you can access array here, because it is declared globally
}
Additionally, have a look at this MSDN article about scope in C#.