EnemyBase.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. public abstract class EnemyBase : EntityBase {
  6. internal override void OnUpdate() {
  7. rb.mass = baseMass * (towardsRight ? 1.2f : 0.8f);
  8. // 反向
  9. if (towardsRight != (Mathf.Abs(rb.velocity.x) > filpSpeed ? rb.velocity.x > 0 : towardsRight)) {
  10. towardsRight = !towardsRight;
  11. transform.DOScaleX(towardsRight ? 1 : -1, 0.15f);
  12. }
  13. }
  14. public bool movingLeft = false;
  15. internal override void OnHitBorder() {
  16. // 死亡
  17. Modules.DestroyGameObject(gameObject);
  18. }
  19. public int hp; internal int currentHp = -10;
  20. internal override void OnHitBullet() {
  21. // 受伤动画
  22. sprite.DOColor(new Color(1f, 0.5f, 0.5f), 0.04f).SetLoops(2, LoopType.Yoyo);
  23. // 死亡判断
  24. if (currentHp == -10) currentHp = hp;
  25. currentHp--;
  26. if (currentHp <= 0) {
  27. AudioM.Play("enemy_die", 0.7f);
  28. Modules.DestroyGameObject(gameObject);
  29. if (hp > 3) { Camera.current.DOShakePosition(0.15f, 0.4f, 100).SetId("ScreenShake"); }
  30. }
  31. }
  32. }