/// <summary> /// Checks whether the user is pressing any action key and invokes the corresponding method. /// Action keys: R = (Reload), Mouse1 = (Aim), F = (Melee Attack). /// </summary> private void GetUserInput() { // Restrictions to reload. bool canReload = nextReloadTime < Time.time && !reloading && currentAmmo < magazineSize && magsRemaining > 0 && !fighting && !controller.isClimbing && nextVaultTime < Time.time; if (canReload) // If there is no restriction to reload. { if (Input.GetKeyDown(KeyCode.R)) { Reload(); } } // Restrictions to shoot. bool canFire = nextFireTime < Time.time && nextReloadTime < Time.time && currentAmmo >= 0 && !reloading && controller.moveState != MoveState.Running && !fighting && !controller.isClimbing && nextVaultTime < Time.time; if (canFire) // If there is no restriction to shoot. { if (isFiring()) // Is requesting to shoot? { if (currentAmmo == 0 && magsRemaining > 0) // If the magazine is empty and have bullets to reload. { Reload(); } else if (currentAmmo > 0) // If the player have bullets available to shoot. { Shot(); } else if (currentAmmo == 0 && magsRemaining == 0) // Out Of Ammo. { weaponManager.OutOfAmmo(); } } } else { if (reloading && reloadStyle == ReloadStyle.BulletByBullet && controller.moveState != MoveState.Running && currentAmmo > 0) { if (Input.GetKeyDown(KeyCode.Mouse0)) // Stops Bullet By Bullet reload. { StopCoroutine(ReloadBulletByBullet()); StartCoroutine(StopReloadBulletByBullet()); } } } // Restrictions to aim. bool canAim = !reloading && aimDownSights && !fighting && !controller.isClimbing && nextVaultTime < Time.time; if (canAim) // If there is no restriction to aim. { if (Input.GetKeyDown(KeyCode.Mouse1) && !aiming) { aiming = true; } else if (Input.GetKeyDown(KeyCode.Mouse1) && aiming) { aiming = false; } } else { aiming = false; } // Restrictions to do melee attack. bool canMelee = melee && !reloading && !fighting && nextReloadTime < Time.time && controller.moveState != MoveState.Running && !controller.isClimbing && nextVaultTime < Time.time; if (canMelee) // If there is no restriction to do melee attack. { if (Input.GetKeyDown(KeyCode.F)) { StartCoroutine(MeleeAttack()); } } }