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

public class DodgingState : MonoBehaviour
{
    public IdleState IdleState;
    public CharacterController Controller;
    public Animator Animator;
    public float DodgeSpeed;
    [HideInInspector] public Vector3 Direction;
    private float timer;
    public float Duration;
    public ParticleSystem TrailFX;

    // Start is called before the first frame update
    void OnEnable()
    {
        timer = 0;
        Vector3 target = Controller.transform.position + Direction;
        target.y = 0;
        Controller.transform.LookAt(target);
        if(TrailFX != null) 
            TrailFX.Play(true);
        if(Animator != null)
            Animator.Play("Base Layer.Slide");
        
    }

    void OnDisable()
    {
        if(TrailFX != null) 
            TrailFX.Stop(true);
    }


    // Update is called once per frame
    void Update()
    {
        Controller.Move(Direction * DodgeSpeed * Time.deltaTime);
        timer += Time.deltaTime;
        if(timer > Duration)
        {
            enabled = false;
            IdleState.enabled = true;
        }
    }
}
