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 window:
Figure 6.4 – Setting Default Behaviour Mode to 2D
- Import the provided image; that is, EnemyBug.png.
- Drag an instance of the red Enemy Bug image from the Project | Sprites folder into the scene. Position this GameObject at (0, 0, 0) and scale it to (2, 2, 2).
- Create a C# script class called BugFlip and add an instance object as a component of Enemy Bug:
using UnityEngine;
using System.Collections;
public class BugFlip : MonoBehaviour {
private bool facingRight = true;
void Update() {
if (Input.GetKeyDown...