using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float moveSpeed;
private Animator anim;
private bool PlayerMoving;
private Vector2 LastMove;
private Rigidbody2D myRigidBody;
// Use this for initialization
void Start () {
myRigidBody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
PlayerMoving = false;
if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f )
{
// transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
myRigidBody.velocity = new Vector2(Input.GetAxisRaw("Horizontal"), myRigidBody.velocity.y) * moveSpeed;
PlayerMoving = true;
LastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
}
if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
{
// transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
myRigidBody.velocity = new Vector2(myRigidBody.velocity.x, Input.GetAxisRaw("Vertical")) * moveSpeed;
PlayerMoving = true;
LastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
}
if (Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
{
myRigidBody.velocity = new Vector2(0f, myRigidBody.velocity.y);
}
if (Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f)
{
myRigidBody.velocity = new Vector2(myRigidBody.velocity.x, 0f);
}
anim.SetFloat("moveX", Input.GetAxisRaw("Horizontal"));
anim.SetFloat("moveY", Input.GetAxisRaw("Vertical"));
anim.SetFloat("LastMoveX", LastMove.x);
anim.SetFloat("LastMoveY", LastMove.y);
anim.SetBool("PlayerMoving", PlayerMoving);
}
}