살인마에게 가격당한 생존자는 이동할 때, 혈흔을 남기는데 언리얼의 데칼 시스템으로 구현할 수 있다.
ADecalActor
와 타이머로 부상상태일 때, 주기적으로 혈흔을 남기도록 설정했다.
void USurvivorStatComponent::BeginPlay()
{
Super::BeginPlay();
GetWorld()->GetTimerManager().SetTimer(BloodTimerHandle, this, &USurvivorStatComponent::SpawnBloodDecalActor, BloodRate, true, BloodRate);
PauseBloodTimerHandle();
}
void USurvivorStatComponent::SpawnBloodDecalActor()
{
FVector DecalSpawnLocation = FVector(Survivor->GetActorLocation().X, Survivor->GetActorLocation().Y, 0.0f);
FRotator DecalSpawnRotation = FRotator(0.0f, 0.0f, Survivor->GetActorRotation().Yaw);
BloodDecal = GetWorld()->SpawnActor<ADecalActor>(DecalSpawnLocation, DecalSpawnRotation);
if (BloodDecal != nullptr)
{
BloodDecal->SetDecalMaterial(BloodDecalMaterial);
BloodDecal->SetLifeSpan(3.5f);
BloodDecal->GetDecal()->DecalSize = FVector(120.0f, 120.0f, 120.0f);
}![](https://velog.velcdn.com/images/wlsry45963/post/54a79056-c42c-4361-a549-ac1e3ba57d55/image.gif)
}
void USurvivorStatComponent::PauseBloodTimerHandle()
{
GetWorld()->GetTimerManager().PauseTimer(BloodTimerHandle);
}
void USurvivorStatComponent::UnPauseBloodTimerHandle()
{
GetWorld()->GetTimerManager().UnPauseTimer(BloodTimerHandle);
}
BeginPlay
에서 혈흔 타이머를 설정한다. SpawnActor
로 데칼을 생성하고 SetDecalMaterail
, SetLifeSpan
, 데칼의 DecalComponent
에서 DecalSize
를 조정하여 혈흔의 수명과 크기, 머티리얼을 설정한다.
PauseTimer
, UnPauseTimer
로 Timer동작을 설정할 수 있다.