| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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<ParticleSystem>();
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.tag == "Player")
- {
- drainCoroutine = DrainPower(other.GetComponent<Player>());
- 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;
- }
- }
- }
|