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

public class WeaponEnemy : MonoBehaviour
{
    public float powerSuckDelay = 0.3f;
    private IEnumerator drainCoroutine;

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            drainCoroutine = DrainPower(other.GetComponent<Player>());
            StartCoroutine(drainCoroutine);
        }
    }

    void OnTriggerExit(Collider other)
    {
        if (other.tag == "Player")
        {
            if (drainCoroutine != null)
                StopCoroutine(drainCoroutine);
        }
    }

    private IEnumerator DrainPower(Player player)
    {
        while (true)
        {
            yield return new WaitForSeconds(powerSuckDelay);

            player.PowerLevel -= 1.0f;
        }
    }

}
