how to index through game objects?

GameObject bullets = GameObject.FindGameObjectsWithTag(“bullet”);

		if (transform.position.x == bullets*.transform.position.x){*

_ transform.Translate(Vector3.right * Speed * Time.deltaTime);_

  •  	i++;*
    
  •  }*
    

i want to be able to check the npc’s position relative to the bullets’ position and since there’s multiple bullets I need to index them but I don’t know why this code isnt working. Or if theres a better way to do this without having to put all the bullets into the array. the code is way more complex than this and theres a lot more conditions but I just need to know how to index through all the bullets correctly.

You’re only looking at one bullet. Try using a while loop or a for loop. C#:

for(int i = 0; i < bullets.Length;i++){
    if (transform.position.x == bullets*.transform.position.x){*

transform.Translate(Vector3.right * Speed * Time.deltaTime);
}
}
JS:
for (var i = 0;i < bullets.length;i++){
if (transform.position.x == bullets*.transform.position.x){*
transform.Translate(Vector3.right * Speed * Time.deltaTime);
}
}