Hi,
I’ve basically got this little script that is supposed to cycle through enemies whenever I press the shift key.
It does this, but since the List used to store the enemies keeps changing in size rather fast.
A simple counter runs into index out of range errors, seemingly because when the list would be filled like this: element 0=A, 1=B, 2=C And have enemy C selected, enemy A can suddenly drop out of the list.
Making the list count 2, while I’m trying to select the third, now non existing element. I believe this is the reason why I keep getting these errors, but I’ll post a snippet anyway.
function switchLockOnTarget()
{
if(Input.GetKeyDown(KeyCode.LeftShift))
{
if(curLockOn+1>=lockOnTargets.Count)
{
curLockOn = 0;
}
else if(curLockOn+1<=lockOnTargets.Count)
{
curLockOn = curLockOn+1;
}
}
}
Am I missing something simple here, or do I need to consider using different methods of cycling through the list?
Thanks in advance,
~Nick