Hi, My game has a gameobject [,] that I want to mix. This code is working only array: Code (CSharp): public static void ShuffleArray<T>(T[] arr) { for (int i = arr.Length - 1; i > 0; i--) { int r = Random.Range(0, i); T tmp = arr[i]; arr[i] = arr[r]; arr[r] = tmp; } } but I use matrix. how do i do this..
You can do this two ways: 1. copy the 2-dimensional GameObject array into a temporary one-dimension array, use the above shuffle routine, and then copy it back to the 2-dimensional array OR 2. change the above to iterate i and j (nested for loops) and choose an r (and perhaps an r2) that satisfies the necessary "don't pick beyond where I have iterated yet" rule. Probably easiest to do #1 honestly.