Hey, guys! I got into Unity really recently and I have been working on a simple game. So simple, I don’t even want to move my character throughout the level. I just need to make him flip everytime I press the Left and Right arrow keys. I’ve been learning some stuff here and there and searching everywhere but it’s not enough for me to understand this yet, so I needed your help! I’m sorry if I look like I’m making you do all the work, it’s not my wish to do so! I have this piece of code but I need to know where to change exactly so I can use the arrow keys and make him JUST flip and not move.
using UnityEngine;
using System.Collections;
public class FlipCharacter : MonoBehaviour {
public float maxSpeed = 1f;
bool facingRight = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate ()
{
float move = Input.GetAxis ("Horizontal");
GetComponent<Rigidbody2D>().velocity = new Vector2 (move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);
if(move > 0 && !facingRight)
{
Flip ();
}
else if(move < 0 && facingRight)
{
Flip ();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
If you need anything more, tell me! Thanks in advance!