well first of all i would assume your game has a master script attached to something neutral other than the cars. if not, you will need one at somepoint before you finish.
so lets assume you have a javascript attached to the camera called “masterscript”. and then the cars could report positions or variable to that script for calculation.
so each cars individual script would say at the top above update something like this:
var cam:GameObject;
cam=gameObject.Find("Main Camera");
var mscript: level = cam.GetComponent(level);
mscript = cam.GetComponent(level);
obviosly each car should have a variable in its script to somehow know what car number it is.
var carnumber:int;
if(transform.name=="object0"){carnumber=0;}
if(transform.name=="object1"){carnumber=1;}
if(transform.name=="object2"){carnumber=2;}
set up an array in the masterscript to recieve car positions. if you know you always have eight car its as simple as this:
var carpositions:float[];
carpositions=new float[8];
now that you have this set up, each car reports stuff into the array on the master script with this:
var distancefromstartline:float;
mscript.carpositions[carnumber]=distancefromstartline;
now if you’re still following me you should have a happy array of all the car positions neatly packed into one script to display or do whatever.
arrays are really cool and are very handy
there are many ways to do it but here is an example of pageing through the array to find your highest car!
var winningcarnumber:int;
var f:float;
var i:int;
i=carpositions.Length;
f=0;
while(i>0){i=i-1;
if(carpositions_>f){f=carpositions*;*_
winningcarnumber=i;}
}
keep in mind that if you have 8 cars. the first car is zero. your array is 0-7; there is not an 8. its best to name them all accordingly to keep things uniform in your project.
hope this all helps to get you thinking in the right direction. your masterscript could simply display the winning car number on screen or even all positions or whatever. that’s another question!