Array sorting issues - Please Help!!!

Hello I have an issue with this script. I have 8 GameObjects, which each share a common script called “Waypoint Progress Tracker” (C#) attached to them, with a public variable “progressDistance” in the script. I have a second script called “Array” (Js) which has the following information in it:

var Cars : GameObject;

function Update ()

System.Array.Sort(Cars, CompareCondition);

function CompareCondition(carA: GameObject, carB: GameObject): int

var scriptA = carA.GetComponent("WaypointProgressTracker");
var scriptB = carB.GetComponent("WaypointProgressTracker"); 
if (scriptA.progressDistance > scriptB.progressDistance) return -1;
if (scriptA.progressDistance < scriptB.progressDistance) return 1;
return 0;

Everything works up until the if-statements. I get the error:

BCE0019: ‘progressDistance’ is not a member of ‘UnityEngine.Component’.

Can anyone help me? Im trying to sort (ascending ) the array of GameObjects based on the “progressDistance” variables.

I think it might be similar to this

So scriptA and scriptB are both fine but their variable progressDistance isn’t? That’s weird. I feel like scriptA and scriptB still shouldn’t be reached since you used quotations for GetComponent.

Say, what if it’s about the compiler time? Make sure the C# script is compiled before Array.js.

The GetComponent( string name ) function returns a component object. To make it useable as the specific component you want, you have to explicitly cast it.

var scriptA = carA.GetComponent("WaypointProgressTracker") as WaypointProgressTracker;

Alternatively you could use the generic version

Ok I finally figured it out lol. I just took out “#pragma strict” and it now works perfectly with the script I originally posted. Geesh all that time that line just needed to be deleted smh. Thank you two for your help though!!!