Can someone assist me in understanding the cause of this error?
IndexOutOfRangeException: Array index is out of range.
(at Assets/Scripts/PlayerCar.js:73)
CompareApproximately (det, 1.0F, .005f)
UnityEditor.DockArea:OnGUI()
Snippet from My code:
var GearRatio : float [ ];
var CurrentGear :int= 1;
var EngineTorque:float=230.0;
var MaxEngineRPM:float=3000;
var MinEngineRPM:float=1000;
private var EngineRPM: float = 0.0;
function Start () {
rigidbody.centerOfMass += Vector3(0, -1f, 0.25f);
}
function Update () {
EngineRPM =( FrontLeftWhell.rpm + FrontRightWhell.rpm)/2 * GearRatio[CurrentGear];
ShiftGears();
FrontLeftWhell.motorTorque = (EngineTorque /GearRatio[CurrentGear]) * motorInputTouch;
FrontRightWhell.motorTorque = (EngineTorque /GearRatio[CurrentGear]) * motorInputTouch;
}
function ShiftGears(){
if(EngineRPM>=MaxEngineRPM){
var AppropriateGear: int =CurrentGear;
for (var i=0;i<GearRatio.length;i++){
if(FrontLeftWhell.rpm * GearRatio[i]>MaxEngineRPM){
AppropriateGear=i;
break;
}
}
CurrentGear=AppropriateGear;
}
if(EngineRPM <=MinEngineRPM){
AppropriateGear=CurrentGear;
for (var j=0;j<GearRatio.length;j++){
if(FrontLeftWhell.rpm * GearRatio[j]>MinEngineRPM){
AppropriateGear=j;
break;
}
}
CurrentGear=AppropriateGear;
}