Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm toying around with the new Sprite class in Unity, and I'm trying to work out how to change the direction the sprite is facing ("flip" it). I'm sure I can most likely just scale it across the x axis by -1, but I'd just like to know if there's a new, "official" way of doing it with Sprite or SpriteRenderer. Thanks!

share|improve this question
    
flip the texture –  concept3d Dec 9 '13 at 6:19
    
Note that simple flipping leads to ambidextrous sprites, which may or may not be appropriate for the game you're making. If you want to avoid that, you'll either need a perfectly symmetric sprite, or a seperate (set of) sprites for the reverse direction. –  Michael Madsen Dec 10 '13 at 10:45
add comment

4 Answers

Looks like the "official" way is to just invert the scale across the x axis. (That's how it's done in the 2D project example, so I think it's safe to assume there's no fancier way of doing it.)

share|improve this answer
add comment

You should aim to keep the scale of your "containers" like the root of the character at (1,1,1). So I recommend having the sprite as a child of the gameobject, you don't want changing the scale of the sprite affecting the collider for example. Then flip the scale of that child.

share|improve this answer
    
I second this, when scaling the x your rotations will reverse as well. If you want to flip the sprite and save yourself a lot of headache, make it a child and scale the child's x to -1. –  Heckman Mar 7 at 16:33
add comment

Per the Unity 4.3 - 2D Game Walkthrough at about 8:15, their implementation of the Flip() function to reverse the character sets the x scale to -1

share|improve this answer
add comment

Like others said, you can flip the x value of the local scale:

var direction = 1; //  or -1, depending which way you want the sprite pointing.

// Sets the local scale of the current GameObject
transform.localScale = new Vector3(direction, 1, 1);

(Try flipping the y value too!)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.