From 7c445980849e60776a3f6b2d933a1867bb1d373d Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Wed, 18 Jan 2023 00:35:06 +0000 Subject: [PATCH] Play Weapon Fire Sound in OnFire --- Source/Nakatomi/PlayerCharacter.cpp | 5 +++-- Source/Nakatomi/Weapon.cpp | 9 +++++++++ Source/Nakatomi/Weapon.h | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 4610d27..73dea4a 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -384,7 +384,6 @@ void APlayerCharacter::RemoveWeaponFromInventory(int i) void APlayerCharacter::RemoveCurrentWeaponFromInventory() { // TODO: Add more checking here - } void APlayerCharacter::OnFire() @@ -406,7 +405,9 @@ void APlayerCharacter::OnFire() RemoveCurrentWeaponFromInventory(); } - // TODO: Play sound effect + CurrentWeapon->PlayFireSoundAtLocation(GetActorLocation()); + + // TODO: Play some animation here CurrentWeapon->SetCurrentWeaponStatus(WeaponState::Cooldown); } diff --git a/Source/Nakatomi/Weapon.cpp b/Source/Nakatomi/Weapon.cpp index 6fe24e7..d9bf82c 100644 --- a/Source/Nakatomi/Weapon.cpp +++ b/Source/Nakatomi/Weapon.cpp @@ -2,6 +2,7 @@ #include "Weapon.h" +#include // Sets default values AWeapon::AWeapon() @@ -68,6 +69,14 @@ void AWeapon::SetFireSound(USoundBase* USoundBase) FireSound = USoundBase; } +void AWeapon::PlayFireSoundAtLocation(FVector location) +{ + if (!FireSound) + { + UGameplayStatics::PlaySoundAtLocation(this, FireSound, location); + } +} + int AWeapon::GetAmmoCount() { return AmmoCount; diff --git a/Source/Nakatomi/Weapon.h b/Source/Nakatomi/Weapon.h index 0bc923c..ea5d218 100644 --- a/Source/Nakatomi/Weapon.h +++ b/Source/Nakatomi/Weapon.h @@ -104,6 +104,8 @@ public: void SetFireSound(USoundBase* USoundBase); + void PlayFireSoundAtLocation(FVector location); + int GetAmmoCount(); void SetAmmoCount(int ammoCount);