gpt4 book ai didi

javascript - 索引超出范围异常 : Array index is out of range

转载 作者:行者123 更新时间:2023-12-03 10:55:07 24 4
gpt4 key购买 nike

我不明白这个错误的原因是什么,有人可以帮助我吗?

IndexOutOfRangeException:数组索引超出范围。
(位于 Assets/Scripts/PlayerCar.js:73)
比较近似(det、1.0F、.005f)
UnityEditor.DockArea:OnGUI()

我的代码:

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[i]>MinEngineRPM){
AppropriateGear=j;
break;
}
}
CurrentGear=AppropriateGear;
}

最佳答案

我认为,问题就出在这一行

EngineRPM =( FrontLeftWhell.rpm + FrontRightWhell.rpm)/2 * GearRatio[CurrentGear];

    FrontLeftWhell.motorTorque = (EngineTorque /GearRatio[CurrentGear]) * motorInputTouch;
FrontRightWhell.motorTorque = (EngineTorque /GearRatio[CurrentGear]) * motorInputTouch;

关于javascript - 索引超出范围异常 : Array index is out of range,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28285900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com