using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAnimation : MonoBehaviour
{
    private const string IS_RUNNING = "IsRunning";
    private const string IS_JUMPING = "IsJumping";

    private Animator animator;

    [SerializeField] PlayerMovements playerMovements;

    private void Awake() {
        animator = GetComponent<Animator>();
        playerMovements.OnForwardPressed += PlayerAnimation_OnForwardPressed;
        playerMovements.OnJumpPressed += PlayerAnimation_OnJumpPressed;
    }

    private void PlayerAnimation_OnForwardPressed(object sender, EventArgs e) {
        animator.SetBool(IS_RUNNING, true);
    }

    public void StopRunning() {
        animator.SetBool(IS_RUNNING, false);
    }
    
    private void PlayerAnimation_OnJumpPressed(object sender, EventArgs e) {
        animator.SetTrigger(IS_JUMPING);
    }
}
