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

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

    void OnCollisionEnter(Collision collision)
    {
            if (collision.collider.tag == "Player")
            {
                drainCoroutine = DrainPower(collision.collider.GetComponent<Player>());
                StartCoroutine(drainCoroutine);
            }
    }

    void OnCollisionExit(Collision collision)
    {
        if (collision.collider.tag == "Player")
        {
            if (drainCoroutine != null)
                StopCoroutine(drainCoroutine);
        }
    }

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

            player.PowerLevel -= 2.5f;
        }
    }

}
