Hello I am attempting to arrange an array that uses random numbers before sorting them by size in order to then us them based on their order. This is to create a simplistic randomisation for an attack pattern.
The issue:
I have to use random numbers so I need to be using namespaces; UnityEngine for the Random number generation and System.Linq in order to use OrderBy. I cannot use Systems namespace which contains “Array.Sort(Array);” which I know would be easier however does not work with UnityEngine for some reason, elaborate on why this is as well please.
I have got the Orderby code, however I cannot find any documentation on OrderBy anywhere so I cannot find what is required to put instead of the question marks of the code shown below.
I have tried searching around a lot and I have finally given up, code is as shown below, if anyone has a reference to what I am looking for, please share
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
float randomOrder1;
float randomOrder2;
float randomOrder3;
float[] randomOrder;
IEnumerator FireThreeAttack()
{
while (randomOrder1 == randomOrder2 || randomOrder1 == randomOrder3 || randomOrder2 == randomOrder1 || randomOrder2 == randomOrder3 || randomOrder3 == randomOrder1 || randomOrder3 == randomOrder2)
{
randomOrder1 = randomOrder1;
randomOrder2 = randomOrder2 + 1.1f;
randomOrder3 = randomOrder3 - 1.2f;
}
randomOrder = new float[] { randomOrder1, randomOrder2, randomOrder3 };
randomOrder.OrderBy(randomOrder => randomOrder.???????).ToArray(); //what do I put here?
if (randomOrder[0] == randomOrder1 || randomOrder[0] == randomOrder2 || randomOrder[0] == randomOrder3)//this will fire the attack off in the given order, I will change this later to be a while loop to be cleaner but for now I just need the information for the order sorting and I can take it from there, but if anyone spots anything wrong here let me know :D
{
if (randomOrder[0] == randomOrder1)
{
attackBlockMainAnim.SetBool("Fired?", true);
}else { }
if (randomOrder[0] == randomOrder2)
{
attackBlockLeftAnim.SetBool("Fired?", true);
}else { }
if (randomOrder[0] == randomOrder3)
{
attackBlockRightAnim.SetBool("Fired?", true);
}else { }
}