W
W
WasTabon2021-05-27 15:26:45
Unity
WasTabon, 2021-05-27 15:26:45

How can I rotate all child 2d objects?

There is this code

if (joystickMoving.Horizontal < 0f)
        {
            spriteRenderer.flipX = true;
            int count = transform.childCount;
            for (int i = 0; i < count; i++)
            {
                if (transform.GetChild(i).tag == "Head" || transform.GetChild(i).tag == "Leg")
                {
                    SpriteRenderer sprit = transform.GetChild(i).GetComponent<SpriteRenderer>();
                    sprit.flipX = true;
                }
            }
        }
        else if (joystickMoving.Horizontal > 0f)
        {
            spriteRenderer.flipX = false;
            int count = transform.childCount;
            for (int i = 0; i < count; i++)
            {
                if (transform.GetChild(i).tag == "Head" || transform.GetChild(i).tag == "Leg")
                {
                    SpriteRenderer sprit = transform.GetChild(i).GetComponent<SpriteRenderer>();
                    sprit.flipX = false;
                }
            }
        }

As you might guess, I need to make a turn of the head and legs, but here's the problem, when flipping X, the legs take this position
60af8ffba4faa441924322.png
. How can this be solved?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question