Tuesday, August 14, 2018

How to flip a group of sprites using unity

tldr; To flip or mirror a group of sprites, take the parent gameobject, rotate it 180 around the y axis.  All the children attached to it will rotate as well.

I wanted to flip or rotate or mirror a sprite that was composed of a group of child sprites.  Selecting flip on the parent object's renderer didn't seem to work, or rather it flipped that sprite, but not all the children.

In a script attached to the parent object I called:

transform.Rotate(new Vector3(0, 180, 0));

This rotated the sprite and all of its children, so now the entire sprite was facing the opposite direction (right instead of left) .  The animations associated with the sprites were also flipped correctly.

No comments: