- Home /
Question by
sherlockturtle · Mar 27, 2013 at 08:50 PM ·
gameobjectarraysorting
Sort Array Of GameoObjects useing a variable
How could I sort an array of gameobject from greatest to least. Each game object has a script with a number on it. I want to sort that array from one with greatest to least. How could i do this?
Comment
Best Answer
Answer by whydoidoit · Mar 27, 2013 at 08:54 PM
You can do this:
import System.Linq;
...
var sortedArray = originalArray.OrderBy(function(g) g.GetComponent(SomeScript).theNumber).ToArray();
using System.Linq;
var sortedArray = originalArray.OrderBy(element => element.GetComponent<SomeScript>().theNumber).ToArray();
Your answer
Follow this Question
Related Questions
Sorting an Array of GameObjects by Name 1 Answer
How to remove objects from a list ? 3 Answers
Can't add GameObjects to ArrayList 1 Answer
Keep adding targets to a list 2 Answers
Removing objects from an array 2 Answers