Can you mirror a bunch of gameobjects ?

Hi all

I suddenly would like the ability to mirror a bunch of gameobjects, in my case with colliders attached.

any ideas?

Hi Jake :slight_smile:

It’s possible to just set all the scale values to -1 and then rotate your gameobject in the desired axis by 180 degrees.

Here’s one way to mirror objects without adjusting the scale. You can use the public method to switch the master objects that you wish to manipulate.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MirrorGameObjects : MonoBehaviour
{

    public List <Transform> objsToMirror = new List<Transform>();
    public Transform slaveParent;

    private Transform[] masterObjs;
    private Transform[] slaveObjs;

	// Use this for initialization
	void Start ()
    {
        CreateSlaves();
	}
	
	// Update is called once per frame
	void FixedUpdate ()
    {
        MirrorObjects();
	}

    void CreateSlaves()
    {
        if (!slaveParent)
            slaveParent = transform;
        if (objsToMirror.Count < 1)
        {
            foreach (Transform child in transform)
            {
                objsToMirror.Add(child);
            }
        }
            
        masterObjs = objsToMirror.ToArray();
        slaveObjs = new Transform[masterObjs.Length];
        for (int i = 0; i < objsToMirror.Count; i++)
        {
            slaveObjs _= Instantiate(masterObjs*);*_

slaveObjs*.SetParent(slaveParent);*
}

}

void MirrorObjects()
{
for (int i = 0; i < objsToMirror.Count; i++)
{
slaveObjs.localPosition = new Vector3(-masterObjs.localPosition.x, masterObjs_.localPosition.y, masterObjs*.localPosition.z);
slaveObjs.localEulerAngles = new Vector3(masterObjs.localEulerAngles.x, -masterObjs.localEulerAngles.y, -masterObjs.localEulerAngles.z);
}
}*_

public void SwitchMaster()
{
Transform[] temp = masterObjs;
masterObjs = slaveObjs;
slaveObjs = temp;
}
}