1

I need to shuffle a char array and have a string array that contains words "play" and "game" and have some buttons in my game like this: image1

and this is my code:

for (int i = 0; i < Answers.Length; i++) {
                BtnsCharacter = Answers [i].ToCharArray ();
            } 

but I need is to make a mess in my buttons arraignment wile converting to char in random in every level. like the image bellow for example:

image2

How could I do that

masih namdar
  • 25
  • 1
  • 7
  • 6
    Possible duplicate of [Best way to randomize an array with .NET](https://stackoverflow.com/questions/108819/best-way-to-randomize-an-array-with-net) – Sorceri Feb 06 '19 at 18:33

2 Answers2

1
for (int i = 0; i < Answers.Length; i++) {

 char[] BtnsCharacter = Answers [i].ToCharArray ();

 char[] shuffled = BtnsCharacter.OrderBy(n => Guid.NewGuid()).ToArray();
} 
Jaskier
  • 1,075
  • 1
  • 10
  • 33
Nova Jacob
  • 26
  • 1
  • 2
  • 2
    Please explain your answer. Posting only code (especially without comments) helps no one to _understand_ what is happening within the answer. – Jaskier Feb 06 '19 at 19:06
  • Thanks for your answer Symon but system shows me this error: F:\make app\p_amirza\p_amirza\Assets\Scripts\GameManager.cs(37,37): Error CS1061: 'System.Array' does not contain a definition for 'OrderBy' and no extension method 'OrderBy' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp) – masih namdar Feb 07 '19 at 17:12
0

The answer not from Symon. From Me.

Anyway you have to reference the LINQ Namespace

Nova Jacob
  • 26
  • 1
  • 2