private Animator _ainm;
private Rigidbody2D _body;
public float speed = 250.0f;
// Use this for initialization
void Start () {
_body = GetComponent();
_ainm = GetComponent();
}
// Update is called once per frame
void Update ()
{
float deltaX = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
Vector2 movement = new Vector2(deltaX, _body.velocity.y);
_body.velocity = movement;
_ainm.SetFloat("Speed", Mathf.Abs(deltaX));
Debug.Log(deltaX);
if (!Mathf.Approximately(deltaX, 0))
{
transform.localScale = new Vector3(Mathf.Sign(deltaX), 1, 1);
}
}
},