I’m trying to add 5 to the x axis of every object with a certain tag. Here’s what I have so far:

for (var listofrocks : GameObject in GameObject.FindGameObjectsWithTag("Rocks"))
{

}

How would I do that? (Add 5 to the x axis of everything in the variable “listofrocks”)

`
for (var listofrocks : GameObject in GameObject.FindGameObjectsWithTag(“Rocks”))
{
listofrocks.transform.position.x+=5.0;
}

`

Untested code there but I believe that’s how it goes.

first you have to get an array of whatever you want
then you want to iterate through each variable in the array

example:

    var Rocks : GameObject[]; //[] means its an array of w/e, you can use it with alot of things and it's better than Array or Arraylist...
    
    function Update(){
    Rocks = gameObject.FindGameObjectsWithTag("Rocks"); // finds all GOS with tag Rocks
       for(var Rock : GameObject in Rocks){//goes through each gameobject in the array Rocks
         //do stuff to each object in Rocks Here.
         Rock.transform.position.x += 5;
       }
    }