- Home /
 
               Question by 
               Eco-Editor · Aug 19, 2018 at 11:19 AM · 
                listfor-loopobject pooliteratepick up object  
              
 
              Choose 10 items on each iteration
Hello all,
I have a list of 100 wasps in a scene. I need to pick 10 waspss at button press, overall 10 iterations. Once the group of 10 objects was picked they do something.
this is the script:
     public void LessWasps()
     {
         for (int i = Wasps.Count -1; i>10; i--) //i=10 so once all the bees are out this wont work
         {
             WaspDriver wasp = Wasps[i];
             wasp.ResetTargets(false);
             StartCoroutine(SmoothRotate(wasp.gameObject, Quaternion.Euler(0, 180, 0), 1.5f, () =>
             {
                 StartCoroutine(TravelCoroutine(wasp.gameObject, WaspWindowWaypointPosition.Center, PhaseTransitionTime, postAction: () =>
                 {
                     StartCoroutine(TravelCoroutine(wasp.gameObject, Vector3.up * 200 + Vector3.back * 200, PhaseTransitionTime, postAction: () => Destroy(wasp)));
                 }));
             }));
         }
     }
 
               Comment
              
 
               
              Answer by dalessan9 · Aug 19, 2018 at 10:24 PM
This will loop until i < 10 -- i starts at 100 -- so it'll do 91 loops when it's called.
 for (int i = 0; i != 10; i++;)
 {
 // will do 10 loops then stop
 }
Thanks for your answer @dalessan9 However this didn't do the trick for me yet..... and I found something online that might help: https://stackoverflow.com/questions/319973/how-to-get-first-n-elements-of-a-list-in-c
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                