guys,Im new and get and trouble that cant break it out.
I use an IEnumerator with 2 loops
IEnumerator MultyShoot()
{
for (int i = 0; i < firePoints.Length; i++)
{
ObjectPoolFx bulletRocketPoolScr = GameObject.Find("PoolRocketBullet").GetComponent<ObjectPoolFx>();
for (int j = 0; j < bulletRocketPoolScr.poolSize; j++)
{
if ((bulletRocketPoolScr.objs_[j].activeInHierarchy) == false)
{
if (target != null)
{
bulletRocketPoolScr.objs_[j].SetActive(true);// i wana break out this loop when i set this poolObject is true
.......
}
}
break;
}
} yield return new WaitForSeconds(.3f);
}
}
yield break will out IEnumerator not the loop inside, example: for (int i = 0; i < firePoints.Length; i++) if i got 3 firePoints i should active 3 poolObjects in for (int j = 0; j < bulletRocketPoolScr.poolSize; j++)
if using yield break; only active single poolObject.
IEnumerator MultyShoot()
{
bool breakLoop = false; //set it to false so it doesnt break the loop first time
for (int i = 0; i < firePoints.Length; i++)
{
ObjectPoolFx bulletRocketPoolScr = GameObject.Find("PoolRocketBullet").GetComponent<ObjectPoolFx>();
for (int j = 0; j < bulletRocketPoolScr.poolSize; j++)
{
if ((bulletRocketPoolScr.objs_[j].activeInHierarchy) == false)
{
if (target != null)
{
bulletRocketPoolScr.objs_[j].SetActive(true);// i wana break out this loop when i set this poolObject is true
.......
}
}
breakLoop = true; //if you should break the loop set it to true
break; //then break the inner loop
}
if (breakLoop) //checks if we should break the loop
{
breakLoop = false; //sets it to false as we already know to break the loop
break; //breaks the loop
}
}
yield return new WaitForSeconds(.3f);
}
i done it in different way. Using a function to active bullet in pool make it return gameObject, so i no need to use the second loop. But I will consider @RavenOfCode 's solution, thanks guys