PlayerAnimation.cs 1.16 KB
Newer Older
1
2
3
4
5
6
7
8
using UnityEngine;
using System.Collections;

public class PlayerAnimation : MonoBehaviour {

    private Animator animator;
    private Vector2 lastInput = new Vector2(1, 1);
    private int horizontalDir = 1;
9
    private HeroMobility hm;
10

11
12
    // Use this for initialization
    void Start () {
13
        animator = GetComponent<Animator>();
14
        hm = GetComponent<HeroMobility>();
15
    }
16
17
18

    // Update is called once per frame
    void LateUpdate () {
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
        AminateMovement();
    }

    void AminateMovement() {
        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        if (Mathf.Abs(input.x) > 0 || Mathf.Abs(input.y) > 0) {
            lastInput.x = input.x;
            lastInput.y = input.y;
        }
        if(lastInput.x < 0 && input.y == 0) {
            horizontalDir = -1;
        }else {
            horizontalDir = 1;
        }

        animator.SetFloat("X", Mathf.Abs(lastInput.x));
        animator.SetFloat("Y", lastInput.y);
36
        animator.SetFloat("DeltaPos", hm.deltaPos.magnitude);
37
38
39
40
41
        Vector2 scale = transform.localScale;
        scale.x = horizontalDir;
        transform.localScale = scale;
    }
}