Hi all.
I’m trying to create a function that, when called, creates an array of all objects in the scene, iterates through it, and moves everything to another point (keeping relative positions).
I’m almost there, using the code below; it creates a game empty, works out the iteration’s position relative to it, and applies that difference to world 0,0,0. This works for all GameObjects:
var gameObjs : GameObject = FindObjectsOfType(GameObject) as GameObject;
var newEmptyGameObject : GameObject = new GameObject(“master”);
newEmptyGameObject.transform.position = gameObject.transform.position;
for(var thing : GameObject in gameObjs)
{
var tempV3 = thing.transform.position + newEmptyGameObject.transform.position;
thing.transform.position = Vector3(0,0,0) + tempV3;
print(thing.name);
}
(please excuse the lack of formatting, I’m doing this on an old browser at work…)
My problem is, the terrain doesn’t get included in the array, and so isn’t moved along with just about everything else. I think particles are also left. I’m guessing the terrain isn’t a GameObject, but an Object?
I’ve tried changing the “GameObject” parts to “Object”, but then I can’t access the transforms and move everything.
I’m pulling my hair out, can anybody point me in the right direction please?
(p.s I know this is expensive to do; I’ve omitted an if() statement from the for(thing) part, so only root items are moved).
Cheers
Ian