using System;
using UnityEngine;

namespace Nan.Scripts
{
    public class Enemy1Move : MonoBehaviour
    {
        [SerializeField] private float slowFrameCount = 100;
        [SerializeField] private int slowSpeed;
        [SerializeField] private int normalSpeed;
        private int frameCountFromCreate;

        public PlayerControl Player { get; set; }
        public float EnemyMoveSpeed
        {
            get
            {
                if (frameCountFromCreate < slowFrameCount)
                {
                    frameCountFromCreate++;
                    return slowSpeed;
                }
                return normalSpeed + ScoreManager.Instance.CurrentLayer;
            }
        }

        private void Update()
        {
            if (Player == null) return;
            var vectorToPlayer = Player.transform.position - transform.position;
            GetComponent<Rigidbody2D>().velocity = EnemyMoveSpeed * vectorToPlayer.normalized;
        }
    }
}