Im making a 2D shooter, I made the movement script. It can move and jump with groundcheck but i cant figure out how to flip him to the direction hes moving. Plz help. This is my script till now:
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public float playerSpeed; //allows us to be able to change speed in Unity
public bool grounded;
public Vector2 jumpHeight;
public Animator anim;
public bool facingRight;
public bool facingLeft;
bool paused;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
if (Input.GetKey (KeyCode.D)) {
transform.Translate (7f*Time.deltaTime, 0f, 0f);
}
if (Input.GetKey (KeyCode.A)) {
transform.Translate (-7f * Time.deltaTime, 0f, 0f);
}
if (!grounded && GetComponent<Rigidbody2D> ().velocity.y == 0) {
grounded = true;
}
if (Input.GetKeyDown (KeyCode.A)) {
transform.Translate (1 * playerSpeed * Time.deltaTime, 0f, 0f);
}
if (Input.GetKey (KeyCode.A) || (Input.GetKey (KeyCode.D))) {
anim.Play ("Run");
}
if (Input.GetKeyUp (KeyCode.A) || (Input.GetKeyUp (KeyCode.D))) {
anim.Play ("Idle");
}
if (grounded == true && Input.GetKeyDown (KeyCode.Space)) { //makes player jump
GetComponent<Rigidbody2D> ().AddForce (jumpHeight, ForceMode2D.Impulse);
anim.Play ("Jump");
grounded = false;
}
if (Input.GetKeyDown (KeyCode.Escape)) {
paused = !paused;
}
if (paused)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
}