0

I have a list of GameObjects, those GameObjects have a script attached to it with a score.
I also have a grid that is filled with panels (those panels are the GameObjects from the GameObject list)
The list is being sorted how i want it to, now i want to set the index of those panels so that they are also sorted on the score.
But i'm not sure how to get the right index from that list, i was thinking of using Linq but that's pretty much as far as i came.

So, i have a list in C# and a list in a grid (UI). The panels from the grid list are the same as the GameObject list in the C#.
I need to get the index from the C# list and use that index on the grid list.

public List<GameObject> ScoreObjectList = new List<GameObject>();

    ScoreObjectList = ScoreObjectList.OrderByDescending(x => x.GetComponent<ScoreObjectInfo>().Score).ToList();

That sorts the C# list.

/// C# list.       Grid List
/// [0].Score(55)  [0].Score(1)
/// [1].Score(1)   [1].Score(55)

A visual aspect to my question, as you can see the C# list is sorted with the highest score at the top but the Grid list is not.
I need to get the panel that has the score of 55 and set that index to the index where the score is also 55 in the C# list.
Which should end up looking like this:

/// [0].Score(55)  [0].Score(55)
/// [1].Score(1)   [1].Score(1)
Simon
  • 385
  • 4
  • 19

0 Answers0