Hi everyone,
My unit build script gives an argument out of range exception when my unit queque list (unitName) has 2 or more units in it. For some reason it won’t give the error when I only have one unit in my unitName list.
Does anyone have any clue what the problem can be ? This is bugging me for a few days now.
Below is the code and the error message.
Thanks in advance
void Start()
{
StartCoroutine ("Delayer");
}
}
void UnitBuild()
{
if (unitName.Count > 0) {
if (P1game.creditsUp1 >= unitPrice [0]) { //unit price
P1game.creditsUp1 -= unitPrice [0];
buildEnable = false;
}
}
}
void SpawnUnit ()
{
Debug.Log("spawn unit");
SpawnBullet ();
}
}
void SpawnBullet()
{
Debug.Log("spawn bullet");
unitName.RemoveAt(0);
unitPrice.RemoveAt(0);
buildEnable = true;
}
IEnumerator Delayer()
{
while (true) {
yield return new WaitForSeconds (1);
if (buildEnable) {
UnitBuild ();
}
else
{
SpawnUnit ();
}
}
the error message ;
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
SpawnUnitG.UnitBuild () (at Assets/Scripts/GAMEscene/SpawnUnitG.cs:162)
SpawnUnitG+c__Iterator7.MoveNext () (at Assets/Scripts/GAMEscene/SpawnUnitG.cs:264)