I'm having a strange problem in my scripts... I have one function that is:
function Fire()
{
while(true)
{
yield WaitForSeconds(delay);
Instantiate (bullet, transform.position, transform.rotation);
}
}
This one works fine (BTW I call it in start, not update). Now this one crashes my game every time I load it:
function SpawnEnemy()
{
while(true)
{
if(enemyCount < limit)
{
yield WaitForSeconds(delay);
random = Random.Range(lowerBound,upperBound);
switch(random)
{
case 1:
if(firstPoint != null)
{
x = firstPoint.transform.position.x;
y = firstPoint.transform.position.y;
rotate = firstPoint.transform.rotation;
time = 0;
}
break;
case 2:
if(secondPoint != null)
{
x = secondPoint.transform.position.x;
y = secondPoint.transform.position.y;
rotate = secondPoint.transform.rotation;
time = 0;
}
break;
case 3:
if(thirdPoint != null)
{
x = thirdPoint.transform.position.x;
y = thirdPoint.transform.position.y;
rotate = thirdPoint.transform.rotation;
time = 0;
}
break;
case 4:
if(fourthPoint != null)
{
x = fourthPoint.transform.position.x;
y = fourthPoint.transform.position.y;
rotate = fourthPoint.transform.rotation;
time = 0;
}
break;
}
Instantiate(enemy,Vector3(x,y,0),rotate);
enemyCount ++;
}
}
}
I have no idea what the problem is...