using UnityEngine;

namespace ScrambleKit.Move.AI
{
    [RequireComponent(typeof(MoveInputSource))]
    public class AIRandomlyJump : MonoBehaviour
    {
        public float Interval = 1.5f;
        public float Variance = 0.5f;

        private MoveInputSource input;
        private float nextJumpTime;
        private const string MOVEUP = "MoveUp";

        void Start()
        {
            input = GetComponent<MoveInputSource>();
            PickNextJumpTime();
        }

        void Update()
        {
            if (Time.fixedTime >= nextJumpTime)
                Jump();
        }

        private void Jump()
        {
            input.AITrigger(MOVEUP);
            PickNextJumpTime();
        }

        private void PickNextJumpTime()
        {
            nextJumpTime = Time.fixedTime + Interval + Random.Range(-Variance, Variance);
        }

    }
}