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

public class DumbEnemy : MonoBehaviour, IEnemy
{
    public GameObject Player;
    public int StartHealth = 100;

    private new Rigidbody rigidbody;
    private CenterBar bar;

    public int Health { get; set; }

    public void Start()
    {
        rigidbody = GetComponent<Rigidbody>();
        rigidbody.velocity = new Vector3(0, 0, -3);
        bar = GetComponentInChildren<CenterBar>();
        Health = StartHealth;
    }

    public void Update()
    {
        if (Health <= 0)
        {
            ScoreKeeper.Score++;
            Destroy(gameObject);
        }
        bar.SetValue((float)Health / StartHealth);
    }

    public void FixedUpdate()
    {
        var direction = Player.transform.position - transform.position;
        rigidbody.velocity = (rigidbody.velocity + direction).normalized * 3;
    }
}
