using System.Collections; using System.Collections.Generic; using UnityEngine; public class WeaponEnemy : MonoBehaviour { public float powerSuckDelay = 0.3f; private IEnumerator drainCoroutine; ParticleSystem particles; void Awake() { particles = GetComponent(); } void OnTriggerEnter(Collider other) { if (other.tag == "Player") { drainCoroutine = DrainPower(other.GetComponent()); StartCoroutine(drainCoroutine); particles.Play(); particles.Emit(15); } } void OnTriggerExit(Collider other) { if (other.tag == "Player") { if (drainCoroutine != null) StopCoroutine(drainCoroutine); particles.Stop(); } } private IEnumerator DrainPower(Player player) { while (true) { yield return new WaitForSeconds(powerSuckDelay); player.PowerLevel -= 1.0f; } } }