✅ Creating a memory game! But a function always makes the last vector in array (0,0,0)?
So I've been building langauge learning activtities for English and Japanese speakers on VR Chat. This project is using Unity and Udon Sharp (VR chat friendly C#). I am currently building a memory game where there is a grid of 16 cards with 8 pairs of words. Take a look at the pictures.
In U#, you're not able to use lists or dictionaries... which isnt great. Everything ends up being arrays.
This function randomizes the order of elements in a array of vectors that allows me to then place the cards in random order. However, for some reason this functions always causes the last vector in the array to be (0f, 0f, 0f).... What I ended up doing is bumping up the number of elements to the array to 17 and just never using the last one... but this is janky...
I know there are much better algorithms to shuffle an array, and I`m open to checking those out too. But part of me is really curious why this is happening. It uses Unity's Random.Range to choose a random spot on the array and try to move the first original array element there. If it fails, it tries the next spot until it finds and open place. I put 20 for the amount of attempts it can make which is unnecessary, but if at any point one attempt loops all the way around it leaves the while loop.
I just tried to include the information that was necessary. Just started programming daily with C# a month or two ago, and it's my first time posting here, and I currently hate this function. So any advice, comments, suggestions, or insights are welcome.
よろしくお願いします
In U#, you're not able to use lists or dictionaries... which isnt great. Everything ends up being arrays.
This function randomizes the order of elements in a array of vectors that allows me to then place the cards in random order. However, for some reason this functions always causes the last vector in the array to be (0f, 0f, 0f).... What I ended up doing is bumping up the number of elements to the array to 17 and just never using the last one... but this is janky...
I know there are much better algorithms to shuffle an array, and I`m open to checking those out too. But part of me is really curious why this is happening. It uses Unity's Random.Range to choose a random spot on the array and try to move the first original array element there. If it fails, it tries the next spot until it finds and open place. I put 20 for the amount of attempts it can make which is unnecessary, but if at any point one attempt loops all the way around it leaves the while loop.
I just tried to include the information that was necessary. Just started programming daily with C# a month or two ago, and it's my first time posting here, and I currently hate this function. So any advice, comments, suggestions, or insights are welcome.
よろしくお願いします

