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

public class EnemyFollowPlayerState : EnemyBaseState
{
    private float _timer = 0;
    public override void EnterState(EnemyStateManager manager)
    {

    }

    public override void UpdateState(EnemyStateManager manager)
    {
        if(Vector3.Distance(manager.player.position, manager.transform.position) > manager.enemyLoosePlayerThreshold){
            manager.agent.ResetPath();
            manager.SwitchState(manager.enterIslandState);
            return;
        }
        manager.agent.SetDestination(manager.player.position);
        if(manager.agent.remainingDistance < manager.enemyShootDistanceThreshold && Time.time > _timer){
            Shoot(manager);
        }
    }

    private void Shoot(EnemyStateManager manager)
    {
        _timer = Time.time + manager.shootPeriod;
        GameObject.Instantiate(manager.projectile, manager.shootPos.position, Quaternion.LookRotation(manager.player.position-manager.transform.position));
    }
}
