|
|
@@ -4,6 +4,8 @@ using UnityEngine;
|
|
|
|
|
|
public class Enemy : MonoBehaviour
|
|
|
{
|
|
|
+ public float powerSuckDelay = 1;
|
|
|
+
|
|
|
[SerializeField]
|
|
|
private GameObject powerDrop;
|
|
|
[SerializeField]
|
|
|
@@ -16,6 +18,8 @@ public class Enemy : MonoBehaviour
|
|
|
|
|
|
private DayTimeLabel lastCharging;
|
|
|
|
|
|
+ private IEnumerator drainCoroutine;
|
|
|
+
|
|
|
void OnCollisionEnter(Collision collision)
|
|
|
{
|
|
|
if(!dead)
|
|
|
@@ -24,6 +28,20 @@ public class Enemy : MonoBehaviour
|
|
|
{
|
|
|
Death();
|
|
|
}
|
|
|
+ else 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -98,4 +116,17 @@ public class Enemy : MonoBehaviour
|
|
|
|
|
|
GameObject.Destroy(gameObject);
|
|
|
}
|
|
|
+
|
|
|
+ private IEnumerator DrainPower(Player player)
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ yield return new WaitForSeconds(powerSuckDelay);
|
|
|
+
|
|
|
+
|
|
|
+ player.PowerLevel -= 0.5f;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|