본문 바로가기

언리얼엔진/C++슈팅프로젝트제작

총알 발사 효과음 구현

총알발사음 넣기

언생언리얼교과서 공식 깃허브 자료실/2장으로가서 start-wars-blaster.WAV파일을 누르고 

https://github.com/araxrlab/lifeunreal

 

GitHub - araxrlab/lifeunreal: 인생 언리얼 교과서 공식 예제

인생 언리얼 교과서 공식 예제. Contribute to araxrlab/lifeunreal development by creating an account on GitHub.

github.com

다운받아 Contets드로워에 Audio폴더를 만들고 끌어다 놓습니다.

파일을 열어 소리를 0.2로 줄입니다.

 

총알을 발사하는 Fire()는 playerPawn.cpp에 있으므로 playerPawn.h에 소리를 연결할 fireSound를 선언합니다.

	UPROPERTY(EditAnywhere)
	class USoundBase* fireSound;

playerPawn.cpp에  PlaySound2D()를 위한 헤더파일을 추가하고

#include "Kismet/GameplayStatics.h"

Fire()함수에 PlaySound2D() 사용해 fireSound를 플레이해줍니다.

void APlayerPawn::Fire()
{
	ABullet* bullet = GetWorld()->SpawnActor<ABullet>(
		bulletFactory, firePosition->GetComponentLocation(), firePosition->GetComponentRotation());
	UGameplayStatics::PlaySound2D(GetWorld(), fireSound);
}

fireSound는 BP_PlayerPawn에서 Audio폴더에 있는 wave를 끌어다 연결합니다. BP_PlayerPawn을 컴파일 합니다. 혹시 Fire Sound가 안보이면 언리얼에디터를 끄고 리빌드합니다.

플레이해보면 발사시 총소리가 들릴것입니다.

Bullet.h
0.00MB
PlayerPawn.h
0.00MB
Bullet.cpp
0.00MB
PlayerPawn.cpp
0.00MB

'언리얼엔진 > C++슈팅프로젝트제작' 카테고리의 다른 글

적 방향 결정  (0) 2023.10.19
적 제작하기  (0) 2023.10.19
UE5 플레이어 키입력 바인딩하기  (0) 2023.10.19
플레이어 제작하기  (1) 2023.10.19
슈팅프로젝트 환경 구성  (1) 2023.10.19