void Start() { animator = GetComponent <Animator>(); _FSM = new EnemyFsm(this); _FSM.SetState(new EnemyIdle(_FSM)); meshAgent = transform.parent.GetComponent <NavMeshAgent>(); lifeValue = maxLifeValue; StartCoroutine(ReduceLifeImage()); lifeRedImage.fillAmount = 1; lifeYellowImage.fillAmount = 1; }
private float lifeImageTimer; // 黄色生命值缓慢流血计时器 public void Reduce(GameObject obj, int value) { player = null; if (lifeValue <= 0) { return; } lifeValue -= value; Debug.Log("我被打了,当前生命值:" + lifeValue); if (lifeValue <= 0) { _FSM.SetState(new EnemyDie(_FSM)); lifeValue = 0; OnDie?.Invoke(); } else { _FSM.SetState(new EnemyGetHit(_FSM)); player = obj; } lifeRedImage.fillAmount = (float)lifeValue / maxLifeValue; lifeImageTimer = 0.8f; // 更新计时器 }