Resetting multiple objects position

I found this code linked for resetting an objects position and then modified it to reset the score for my scene but when I apply the script to my multiple objects, it stops working correctly.

var startPos : Vector3;

var startRot : Quaternion;



function Start() {

    startPos = transform.position;

    startRot = transform.rotation;

}



function OnGUI () {

    if (GUI.Button (Rect (10,10,50,25), "Reset")) {

        transform.position = startPos;

        transform.rotation = startRot;

        CollisionSystem.myScore = 0;

    }

}

I’m not entirely sure what I need to modify to make it work correctly.

Any help would be greatly appreciated.

How about something like this:

Create an empty game object & attach the following script to it. Then in the inspector resize the array “myObjects” depending on how many you have & fill the list with you objects. I’m a bit of a noob too so this maybe could be done better, but it’ll work. Hope it helps :slight_smile:

    //  
    var myObjects : GameObject[];  
    private var startPos : Vector3[];  
    private var startRot : Quaternion[];
    
    function Start() {
    
      // resize arrays to match objects array  
      startPos = new Vector3[myObjects.length];  
      startRot = new Quaternion[myObjects.length];  
    
      for (i = 0; i <= myObjects.length - 1; i++) {  
  
        // fill position & rotation arrays for each object in objects array  
        startPos _= myObjects*.transform.position;*_ 

startRot = myObjects*.transform.rotation;*
}
}

function OnGUI(){

for (i = 0; i <= myObjects.length - 1; i++) {

//create a button for each of our
objects in the array & offset position x

if (GUI.Button (Rect (10 + (i * 55), 70, 50, 25), myObjects*.name)) {*

// reset object related to this button
myObjects_.transform.position = startPos*;
myObjects.transform.rotation = startRot;*_

//CollisionSystem.myScore = 0;
}
}

}
//
Here is a small project if you’d like to see it working :slight_smile:
[ResetObjects.zip][1]
_*[1]: Web Hosting, Reseller Hosting & Domain Names from Heart Internet