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

public class RunningState : MonoBehaviour
{
    public CharacterController Controller;
    public Animator Animator;
    public float Speed;
    [HideInInspector] public Vector3 Target;
    public ParticleSystem TrailFX;

    public Transform ModelForEater;
    public float RotationSpeed;

    // Start is called before the first frame update
    void OnEnable()
    {  
        if(TrailFX != null) 
            TrailFX.Play(true);
        if(Animator != null)
            Animator.Play("Base Layer.Runnning");
    }

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

    // Update is called once per frame
    void Update()
    {
        Vector3 target = Target;
        target.y = Controller.transform.position.y;
        Controller.transform.LookAt(target);
        Vector3 direction = (Target - Controller.transform.position).normalized;
        Controller.Move(direction * Speed * Time.deltaTime);

        if(ModelForEater != null)
        {
            ModelForEater.Rotate(ModelForEater.right, RotationSpeed * Time.deltaTime, Space.World);

        }
    }
}
 