- Home /
how can I rotate my all my elements on Z-Axis
Hallo ,how I can rotate all my elments on times vertically
foreach (Bath bath in bathJSON.BathList)
{
//create a new Bath wmv
if (bath.BathTyp == 5)
{
newBath = Instantiate(this.wmv);
//read the postion from Json file
Vector3 wmvPosition = new Vector3
{
x = (bath.X) * mirroringx,
y = bath.Z+2.3f,
z = (bath.Y * scalingz) * mirroringz
};
newBath.transform.position = wmvPosition;
//rotation: the problem is, the elements rotate on them self not on Axis
newBath.transform.RotateAround(newBath.transform.position,Vector3.forward,-90);
newBath.tag = "WMV";
newBath.name = "W_" + bath.Id.ToString();
}
Answer by bdubbert · Nov 12, 2021 at 05:15 PM
Well the easiest way would be to make each unit the child of a single shared parent object, then just rotate the parent once. However if you really want to accomplish this by individual rotations per unit then you need to feed the pivot point into the first argument of RotateAround(). For your example, this pivot point would be a spot directly in between your two units.
In fact, it doesn't really matter what your pivot point is, as long as every unit uses the same pivot point instead of their own pivot point you will have the desired effect. You can play with the position of your pivot point in order to have your final rotation end up in different spots.