Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unity Cookbook - Fifth Edition

You're reading from  Unity Cookbook - Fifth Edition

Product type Book
Published in Nov 2023
Publisher Packt
ISBN-13 9781805123026
Pages 780 pages
Edition 5th Edition
Languages
Authors (3):
Matt Smith Matt Smith
Shaun Ferns Shaun Ferns
Profile icon Shaun Ferns
Sinéad Murphy Sinéad Murphy
Profile icon Sinéad Murphy
View More author details

Table of Contents (22) Chapters

Preface 1. Displaying Data with Core UI Elements 2. Responding to User Events for Interactive UIs 3. Inventory and Advanced UIs 4. Playing and Manipulating Sounds 5. Textures, Materials, and 3D Objects 6. Creating 3D Environments with Terrains 7. Creating 3D Geometry with ProBuilder 8. 2D Animation and Physics 9. Animated Characters 10. Saving and Loading Data 11. Controlling and Choosing Positions 12. Navigation Meshes and Agents 13. Cameras, Lighting, and Visual Effects 14. Shader Graphs and Video Players 15. Particle Systems and Other Visual Effects 16. Mobile Games and Applications 17. Augmented Reality (AR) 18. Virtual and Extended Reality (VR/XR) 19. Advanced Topics – Gizmos, Automated Testing, and More 20. Other Books You May Enjoy
21. Index

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:

  1. 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:

  2. ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime}