ArgumentOutOfRangeException:引数が範囲外です。 パラメータ名:index System.Collections.Generic.List`1 [UnityEngine.Vector3] .get_Item(Int32 index)(/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic) /List.cs:633)資産/ MyScripts/SphereBuilder.csで SphereBuilder.MoveShips()(75)資産/ MyScripts/SphereBuilder.csで SphereBuilder.Update()(65)例外を取得する理由ArgumentOutOfRangeException:引数が範囲外です。
上部にスタート機能でスクリプト
private float distanceTravelled;
public bool updateOn = true;
private List<Vector3> lastPositions = new List<Vector3>();
private List<float> allDistances = new List<float>();
int countpos = 0;
の
private void Start()
{
UpdateSpheres();
spheres = GameObject.FindGameObjectsWithTag("MySphere");
foreach (Transform child in spheres[0].transform)
{
lastPosition = new Vector3(child.transform.position.x,child.transform.position.y,child.transform.position.z);
lastPositions.Add (lastPosition);
}
}
Update関数で
:私は何をしようとしている
void Update()
{
if (updateOn == true) {
//whatever you want update to do.
foreach (Transform child in spheres[0].transform) {
child.transform.position += Vector3.forward * Time.deltaTime * moveSpeed;
Vector3 lp = lastPositions [countpos];
distanceTravelled += Vector3.Distance (child.transform.position, lp);
allDistances = new List<float>();
allDistances.Add (distanceTravelled);
countpos ++;
}
}
if (countpos == spheres.Length)
{
updateOn = false;
distanceTravelled = 0;
countpos = 0;
}
// if you want certain parts of update to work at all times write them here.
foreach (Transform child in spheres[0].transform)
{
child.transform.position += Vector3.forward * Time.deltaTime * moveSpeed;
}
}
はチャイルズは、ポジションを開始し、また、お子様の距離を旅し保存するために格納することです。カウンターでのループで、その後
if (allDistances[0] >= 300000)
{
}
しかし、その代わりにallDistances [0]:
はその後何とか別の関数でたぶん私はループにチャイルズ超えるたびにしたいと、それぞれの子のような特定の距離のものになったかどうかを確認
if (allDistances[counter] >= 300000)
{
}
第1の問題は、範囲外の例外で、なぜ私がそれを取得しているのかわかりません。 球には20個の子供が含まれています。
2番目の問題は、各フレームに移動した距離ごとに各子供をチェックする方法と、子どものいずれかが300000になったときに何かをすることです。
は、例外が発生した行を指定していただけますか? – rbr94
'lastPositions [countpos];'は 'countpos'がリストの長さよりも小さいか0よりも小さいので例外をスローしています。 'countpos'の初期値は何ですか – user3185569
rb94例外は行にありますVector3 lp = lastPositions [countpos]; –