// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _cruiserEnemy._currentSpeed = Mathf.Lerp(_cruiserEnemy._currentSpeed, _targetSpeed, Time.deltaTime * 0.5f); _cruiserEnemy._currentMinTurn += Time.deltaTime * 0.01f; _cruiserEnemy.Move(_targetPos); _cruiserEnemy.TargetPos = _targetPos; if (Vector3.Distance(_transform.position, _targetPos) < _cruiserEnemy.TargetDistanceToPoint) { animator.SetTrigger("Patrolling"); } if (Vector3.Distance(_transform.position, _player.position) < 300) { if (_shieldUp == true) { // Shield Down _shieldUp = false; _cruiserEnemy.shieldDown(); } } else { if (_shieldUp == false) { // Shield Up _shieldUp = true; _cruiserEnemy.shieldUp(); } } }
// Act on the current states logic void Act(Animator animator) { _cruiserEnemy.TargetPos = _player.transform.position; _cruiserEnemy.Move(_player.transform.position); Vector3 toPosition = (_player.position - _transform.position).normalized; float angleToPosition = Vector3.Angle(_transform.forward, toPosition); _cruiserEnemy._currentMinTurn += Time.deltaTime * 0.005f; if (angleToPosition < 1) { if ((_attackTimer += Time.deltaTime) > 6) { _cruiserEnemy.CruiserAttack(); animator.SetTrigger("Escape"); } else { _cruiserEnemy._currentSpeed = Mathf.Lerp(_cruiserEnemy._currentSpeed, _targetAttackSpeed, Time.deltaTime * 0.8f); } } else { _attackTimer = 0.0f; _cruiserEnemy._currentSpeed = Mathf.Lerp(_cruiserEnemy._currentSpeed, _targetSpeed, Time.deltaTime * 0.8f); } if (Vector3.Distance(_transform.position, _player.position) < 300) { if (_shieldUp == true) { // Shield Down _shieldUp = false; _cruiserEnemy.shieldDown(); } } else { if (_shieldUp == false) { // Shield Up _shieldUp = true; _cruiserEnemy.shieldUp(); } } }