C# Rotate GameObjects Regardless of List Size

I have a script that rotates gameobjects in opposite directions. However I can only get a maximum of four gameobjects to rotate. So when for example I add six gameobjects to gameObjectList the last two gameobjects don’t rotate. Is there a way I can get my script to rotate all of the gameobjects within gameObjectList regardless of list size?

			for (int i = 0; i < gameObjectList.Count -1; i+= gameObjectList.Count/2){
				gameObjectList*.Rotate( Vector3.forward, - fSpeed / fDistance);*
  •  		gameObjectList[i+1].Rotate( Vector3.back, - fSpeed / fDistance);*
    
  •  	}*
    

Beans, I believe your problem lies in your for loop. i < gameObjectList.Count - 1' This will stop the loop at the second to last object in your list. If your list has six objects and you add 3 to each object in your code i+= gameObjectList.Count/2then your final linegameObjectList[i+1].Rotate( Vector3.back, - fSpeed / fDistance);`` adds another int those three making it only rotate 4 objects. I hope this helps. I would suggest using a normal for loop. for(int i = 0; i < gameObjectList.Count; i++)

Good Luck!

Rather than playing silly games with your loop counters, why not just do a regular loop, and just flip the direction every other step.

float direction = 1.0f;
foreach(GameObject go in gameObjectList)
{

    go.Rotate( Vector3.forward * direction, - fSpeed / fDistance);
     direction *= -1.0f;

}