using UnityEngine;

public class EnemyController : MonoBehaviour
{

  GameManager gameManager;

  public float duration = 5;
  private float timeRemaining = 5;

  public int pointReward = 0;

  // Start is called once before the first execution of Update after the MonoBehaviour is created
  void Start()
  {
    if (gameManager == null)
    {
      gameManager = FindFirstObjectByType<GameManager>();
    }
  }

  // Update is called once per frame
  void Update()
  {
    timeRemaining -= Time.deltaTime;
    if (timeRemaining <= 0)
    {
      Destroy(gameObject);
      gameManager.NotifyEnemyDeath(0);
    }
  }



  public void SetValues(float duration, int pointReward)
  {
    this.duration = duration;
    timeRemaining = this.duration;

    this.pointReward = pointReward;
  }

  private void OnTriggerEnter(Collider other)
  {
    if (other.CompareTag("Projectile"))
    {
      Destroy(gameObject);
      Destroy(other.gameObject);

      gameManager.NotifyEnemyDeath(pointReward);
    }
  }
}
