public void Action() { //Check if we need to reload if (!_aiWeapon.GetEquippedWeapon().IsReloading) { _aiWeapon.GetEquippedWeapon().Reload(); } }
private void DecideToReload() { //Check if we need to reload if (_aiWeapon.GetEquippedWeapon().NeedToReload) { //Stop firing _aiWeapon.SetFiring(false); //If we are not reloading, then reload the current gun if (!_aiWeapon.GetEquippedWeapon().IsReloading) { //Debug.Log("Reloading"); _aiWeapon.GetEquippedWeapon().Reload(); } //If the AI does not have any bullets left, then switch to the melee state if (_aiWeapon.GetEquippedWeapon().TotalAmmo <= 0) { _agent.stateMachine.ChangeState(AiStateId.Melee); } } }
public void Action() { if (_navAgent.remainingDistance < 1.0f) { //Look at the player when close enough to cover _agent.LookAtLastKnownLocation(); //AI is not standing if (!_isStanding) { _betweenStandingTimer += _betweenStandingDuration; //AI needs to reload if (_aiWeapon.GetEquippedWeapon().NeedToReload) { //Crouch behind cover while reloading _anim.SetBool("isCrouching", true); _aiWeapon.SetTarget(null); _aiWeapon.SetFiring(false); if (!_aiWeapon.GetEquippedWeapon().IsReloading) { _aiWeapon.GetEquippedWeapon().Reload(); } } //AI Does not need to reload else { //Check to see if we can hit the player from the cover RaycastHit hit; if (Physics.Raycast(_agent.transform.position + Vector3.up, _agent.Player.position - _agent.transform.position, out hit, 35.0f, _agent.CharacterMask, QueryTriggerInteraction.Ignore)) { if (hit.collider.CompareTag("Player")) { if (_betweenStandingTimer > _betweenStandingDuration) { //Clear the standing timer _betweenStandingTimer = 0.0f; //Stand up _isStanding = true; _anim.SetBool("isCrouching", false); //Shoot the player _aiWeapon.SetTarget(_agent.Player); if (!_aiWeapon.GetEquippedWeapon().IsFiring) { _aiWeapon.SetFiring(true); } } _changeCoverTimer = 0.0f; } //AI cannot feasibly shoot the player else { TakeCover(); } } //AI can not feasibly shoot the player else { TakeCover(); } } } //AI is standing else { _standShootTimer += Time.deltaTime; if (_standShootTimer > _standShootDuration) { TakeCover(); } } } }