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

public class StartDrift : StateMachineBehaviour
{
    [SerializeField]
    private string endDriftVariableName = "EndDrift";

    [SerializeField]
    private string floatVariableName = "InputX";

    [SerializeField]
    private RacerCore Core;

    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        CheckForCore(animator.transform);

        if (animator.GetFloat(floatVariableName) == 0)
        {
            animator.SetBool(endDriftVariableName, true);
        }
    }

    void CheckForCore(Transform parent)
    {
        Core = parent.GetComponent<RacerCore>();

        if (!Core)
        {
            CheckForCore(parent.parent);
        }
    }

    public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (!animator.GetBool(endDriftVariableName))
        {
            animator.SetBool(endDriftVariableName, !Core.Controller.Drifting);
        }
    }
}
