EnemyBase.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. transform.position = new Vector3(1000, 1000);
  18. gameObject.SetActive(false);
  19. Destroy(gameObject, 1);
  20. }
  21. public int hp; internal int currentHp = -1;
  22. internal override void OnHitBullet() {
  23. // 受伤动画
  24. sprite.DOColor(new Color(1f, 0.5f, 0.5f), 0.04f).SetLoops(2, LoopType.Yoyo);
  25. // 死亡判断
  26. if (currentHp == -1) currentHp = hp;
  27. currentHp--;
  28. if (currentHp <= 0) {
  29. AudioM.Play("enemy_die", 0.5f);
  30. OnHitBorder();
  31. }
  32. }
  33. }