question about foreach loops

Updated on April 2, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
0 on April 2, 2017

Hey guys so I had a question about foreach loops I understand in loops something will be constantly executed until that condition is false. But in my code I go through the transforms under the player and if I press ctrl key it works, shouldn’t every thing else be ignored since the condition isn’t false yet? This is my code as sample. Why is it that I can press the ctrl key? The condition isn’t false yet. Or does it do 1 iteration like scan every object under it then it gets out of the loop goes to top of the script down to the loop eventually?

 if (Input.GetKeyDown(KeyCode.LeftControl))
 {
 bulletInScene = (GameObject)Instantiate(BulletPrefab, bulletPosition.transform.position, Quaternion.identity);
 }
 foreach (Transform t in transform)
 {
 Debug.Log("tester");
 
  • Liked by
Reply