ExplosionDamage.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ExplosionDamage : MonoBehaviour {
  5. public float hitboxDuration = 0.5f; // 碰撞体持续时间.
  6. public float selfDestructTime = 2.0f;
  7. public int power = 10;
  8. public float slowTime = 0;
  9. float timeSinceExplosion = 0; // 开始时间
  10. // Use this for initialization
  11. void Start () {
  12. Destroy(gameObject, selfDestructTime);
  13. }
  14. // Update is called once per frame
  15. void Update () {
  16. timeSinceExplosion += Time.deltaTime;
  17. }
  18. void OnTriggerEnter(Collider other)
  19. {
  20. if (timeSinceExplosion > hitboxDuration) return;
  21. EnemyMovement hitEnemy = other.GetComponent<EnemyMovement>();
  22. if (hitEnemy != null)
  23. {
  24. //Debug.Log(hitEnemy.gameObject.name + ": " + hitEnemy.CurrentHealth + " HP");
  25. hitEnemy.Damage(power);
  26. if (slowTime > 0) hitEnemy.SlowDown(slowTime);
  27. //Debug.Log("Hit " + hitEnemy.gameObject.name + " with " + power + " damage. It has " + hitEnemy.CurrentHealth + " HP left.");
  28. }
  29. }
  30. }