# Comparing values of an array

Hello,

After alot of searching i just can’t seem to find a solution to this problem i’m having.

I have an array which holds the distances of the playercar and the 3 ai cars to the finishline.
How would i go and compare these values, and making a guitext show the players position.

I’m still learning hard, so maybe i’m in way over my head, but it just seems that i’m so close now, but it’s still missing a small vital part

Any help is really appreciated, and here is what i have so far:

var cars : Transform[];
var finish : Transform;
var maxDistance = 0;
var minDistance = 10000;
var distance : float[];

function Update () {

for(i=0; i<4; i++){

distance _= (finish.position - cars*.position).magnitude;*_

if(distance < minDistance)
minDistance = distance*;*
if(distance > maxDistance)
maxDistance = distance*;*
}
}

function OnGUI(){

for(i=0; i<4; i++){

GUILayout.Label("Distance " + i + ": " + distance*);*
}
}

First up, put the line

import System.Collections.Generic;

at the top, to make sure that you have all the classes that you'll need for this.

Now, make a variable called

var sortedCars : SortedList.<Float, Transform>;

This is what you will use to keep track of the cars' positions.

In your Update function, use this:

sortedCars = new SortedList.<Float, Transform>();
for(var carTrans : Transform in cars)
{
var carDistance : float = (finish.position - carTrans.position).magnitude;