Order a GameObject array based on an int property of each object?

public void turnOrder () {

    		GameObject[] playerCharacters;
    		playerCharacters = GameObject.FindGameObjectsWithTag ("ActiveCharacter");
    			playerCharacters = playerCharacters.OrderByDescending (x => x.curAgi).ToList ();

Above is my code, and here’s what I’m trying to achieve:

I’m finding all characters with the tag “ActiveCharacter” and putting them into the array of game objects “playerCharacters”. The goal is to then order them based on their individual “curAgi” values, which is an integer and is unique to each of the characters.

I have used the following:

z = (playerCharacters.Length);
Debug.Log("ArrayLength:" + z);

To confirm that the array has in fact been populated.

The issue appears (I say appears, but it’s rather blatantly obvious considering the error message I am getting and the red highlight) to be with curAgi. Despite being aware of this, I’m at a loss as to the solution. I have looked at previous questions and attempted to follow the advice therein for the past few hours, yet am still coming up blank.

Any and all assistance is very much appreciated.

It seems that you’re trying to access a property (curAgi) that is actually in a script component of the GameObject rather than the object itself. You’d first have to use GetComponent() to get the script with the value that you’re looking for in order to sort them.