Hello guys!
I’m sure the solution of this problem will be pretty simple, but after a lot of research I just can’t make it work. I’m an amateur Unity/C# user, and I don’t quite understand what MSDN says ab
I have a list containing 3 different variables, and what I want to do is simply reorder it with descending “Speed” variable.
public class ActionOrder:IComparer <ActionOrder> {
public int CharacterCounter;
public int Speed;
public bool EnemyAction;
public ActionOrder (int CharacterCounter, int Speed, bool EnemyAction){
this.CharacterCounter = CharacterCounter;
this.Speed = Speed;
this.EnemyAction = EnemyAction;
}
public int Compare (ActionOrder a, ActionOrder b){
if (a.Speed > b.Speed)
return 1;
else if (a.Speed < b.Speed)
return -1;
else return 0;
}
}
public List<ActionOrder> actionOrder = new List<ActionOrder>();
void Start (){
Debug.Log (actionOrder[0].Speed);
Debug.Log (actionOrder[1].Speed);
Debug.Log (actionOrder[2].Speed);
Debug.Log (actionOrder[3].Speed);
actionOrder.Sort();
Debug.Log (actionOrder[0].Speed);
Debug.Log (actionOrder[1].Speed);
Debug.Log (actionOrder[2].Speed);
Debug.Log (actionOrder[3].Speed);
}
This code results in this error, which I also couldn’t figure out what exactly it means:
“ArgumentException: does not implement right interface” and a giant log…
Also, if there’s a simpler method for sorting Lists I would appreciate if you share it.
Cheers!