protected virtual bool AttackTarget(bool _repeatAttack) { if (distanceToTarget <= range) { CurrentState = LivingEntityState.Attacking; attackTime = 1; //animation trigger goes here target.TakeDamage(attackDamage); Debug.Log(gameObject.name + " Attacked " + target.gameObject.name + "!!"); if (!_repeatAttack) { chasing = false; } return true; } else { return false; } }
protected virtual void Update() { switch (CurrentState) { // ==== case LivingEntityState.Idle: if (target && chasing) { if (!AttackTarget(true)) { Move(target); } } else { chasing = false; } break; // ==== case LivingEntityState.Moving: break; // ==== case LivingEntityState.Attacking: agent.destination = transform.position; if (attackTime > 0) { attackTime -= Time.deltaTime; } else { CurrentState = LivingEntityState.Idle; } break; // ==== } }