EnemyBase.cs 744 B

123456789101112131415161718192021222324252627
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. public abstract class EnemyBase : EntityBase {
  6. public bool movingLeft = false;
  7. internal override void OnHitBorder() {
  8. Destroy(gameObject);
  9. }
  10. public int hp; internal int currentHp = -1;
  11. internal override void OnHitBullet() {
  12. // 受伤动画
  13. sprite.DOColor(new Color(1f, 0.5f, 0.5f), 0.04f).SetLoops(2, LoopType.Yoyo);
  14. // 死亡判断
  15. if (currentHp == -1) currentHp = hp;
  16. currentHp--;
  17. if (currentHp <= 0) {
  18. AudioM.Play("enemy_die");
  19. transform.localScale = Vector3.zero;
  20. Destroy(gameObject, 1); // 防止动画没播放完导致报错
  21. }
  22. }
  23. }