- Home /
Check to see if any object in a list meets set of requirements
So I made a list that increases or decreases based on the number of projectiles my enemies have spawned to shoot at me. When any bullet is close enough to my player, the player can shoot the projectiles back at the enemy. Also, when a projectile is close enough I have a 3D text that appears to say the player can do this.
The script I wrote is
if(bulletsList.Count > 0)
{
foreach(GameObject bullet in bulletsList)
{
float dist = Vector3.Distance(bullet.transform.position, transform.position);
print (dist);
if( dist < 8)
{
on = true;
sigCanRoar.SetActive(true);
}
else
{
on = false;
sigCanRoar.SetActive(false);
}
}
}
Issue I'm having is that when I have many projectiles in the list, my script only checks the very first item in the list even though I am running a foreach.
Insert line
print (bulletsList.Count)
how many are there? i.e. prove your list contains what you expect
i verified there are actualy projectiles in the list through the inspector, i even paused the game, clicked each item in the list and it highlighted each corresponding projectile in the hierarchy so i know for sure the list is populated.
Your answer
