Home > Enterprise >  How to flip a composite character in unity 2d?
How to flip a composite character in unity 2d?

Time:05-16

I really need help with Unity 2D. The goal is for the player to flip when going left and back when going right. There are many options on the Internet how to do this through sprite rendering. But the problem is that my character consists of parts, since the animation is bone. Each part can be flipped. And when you turn on flip in the sprite rendering of the object itself, nothing works. The question is how to make a coup at once the entire character? And if not, how to do it in parts?

CodePudding user response:

You should flip via scale, it will effect the all components.It's also metioned in the docs.

CodePudding user response:

As oistikbal said, use scaling like this:

void Update()
{
    if (Input.GetKeyDown(KeyCode.A))
    {
        transform.localScale = new Vector3(-1, 1, 1); ;

    }

    if (Input.GetKeyDown(KeyCode.D))
    {
        transform.localScale = new Vector3(1, 1, 1); ;

    }
}

When A/D is pressed the scale is changed so the character is flipped.

  • Related