Flipping a sprite horizontally – the DIY approach
Perhaps the simplest 2D animation is a simple flip, from facing left to facing right, facing up to facing down, and so on. In this recipe, we’ll add a cute bug sprite to the scene and write a short script to flip its horizontal direction when the Left and Right arrow keys are pressed:
Figure 8.2: Example of flipping a sprite horizontally
Getting ready
For this recipe, we have prepared the image you need in a folder named Sprites
in the 08_01
folder.
How to do it...
To flip an object horizontally with arrow key presses, follow these steps:
- Create a new Unity 2D project.
If you are working on a project that was originally created in 3D, you can change the default project behavior (for example, new Sprite Texture additions and Scene mode) to 2D by going to Edit | Project Settings | Editor and then choosing 2D for Default Behavior Mode in the Inspector panel:
...