I am trying to learn the basics of Unity so I downloaded the latest free version. I created a little place for my character to walk around and a little character (most of which I borrowed from RPG Maker as I am no artist). With that said I created Added a idol and walking animations and hooked them into the animator.
Then I wrote the following:
using UnityEngine;
using System.Collections;
public class character_controller_script : MonoBehaviour {
public float maxSpeed = 10f;
private bool facingRight = true;
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void FixedUpdate () {
// Move at a speed that is predetermined on the Y axis.
float move = Input.GetAxis ("Horizontal");
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
anim.SetFloat ("Speed", Mathf.Abs (move));
if (move > 0 && !facingRight) {
Flip();
} else if(move < 0 && !facingRight) {
Flip();
}
}
// Flips the character based on input.
void Flip() {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Which is pretty basic. We can all understand whats going on here. The issue is simple: The character will move forwards, the character will move backwards, the animations are all linked and work as expected but the character will not flip. So when I move right, he walks. When I move left, it looks like he is walking backwards…
Did I do something wrong in the flip function?
I was watching this tutorial on character control, thats where I got the code from. When he imported his characters they were all right facing, and as far as I understand the code should just flip them for you.
How do I make it flip?