using UnityEngine;
using System.Collections;
public class character : MonoBehaviour {
//movement variables
public float maxspeed;
Rigidbody2D myRB;
Animator myAnim;
bool facingRight
// Use this for initialization
void Start () {
myRB = GetComponent<Rigidbody2D> ();
myAnim = GetComponent<Animator> ();
facingRight = true;
}
// Update is called once per frame
void FixedUpdate () {
float move = Input.GetAxis ("Horizontal");
myAnim.SetFloat ("speed", Mathf.Abs (move));
myRB.velocity = new Vector2 (move * maxspeed, myRB.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;
}
}