Fabrik: Beleuchtung & fertiges Gameplay ;Türen jetzt auch mit Verzögerung
This commit is contained in:
parent
d0e3953ea7
commit
bb34cad8e7
BIN
Content/Audio/Sound/345684__provan9__radio-alert.uasset
Normal file
BIN
Content/Audio/Sound/345684__provan9__radio-alert.uasset
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,7 +2,8 @@
|
||||
|
||||
#include "Components/AudioComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
#include "Engine/World.h"
|
||||
#include "Engine/Public/TimerManager.h"
|
||||
|
||||
URotatingActor::URotatingActor()
|
||||
{
|
||||
@ -34,35 +35,17 @@ void URotatingActor::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
|
||||
|
||||
void URotatingActor::Rotate(const FRotator TargetRotation)
|
||||
{
|
||||
this->targetRotation = TargetRotation;
|
||||
rotating = true;
|
||||
tempRotation = (TargetRotation.Yaw < 0) ? -1.f : 1.f;
|
||||
if (Negative)
|
||||
FTimerHandle handle;
|
||||
|
||||
if(RotationDelay == 0)
|
||||
{
|
||||
tempRotation = (TargetRotation.Yaw < 0) ? 1.f : -1.f;
|
||||
}
|
||||
|
||||
TArray<UAudioComponent*> Audios;
|
||||
GetOwner()->GetComponents<UAudioComponent>(Audios);
|
||||
|
||||
if (Audios.Num() == 0) return;
|
||||
if (soundHasBeenPlayed) return;
|
||||
|
||||
for (auto Audio : Audios)
|
||||
Move(targetRotation);
|
||||
}else
|
||||
{
|
||||
if (Audio->ComponentHasTag("location"))
|
||||
{
|
||||
UGameplayStatics::PlaySoundAtLocation(GetOwner(), Audio->Sound, GetOwner()->GetActorLocation(),
|
||||
GetOwner()->GetActorRotation(), 1, 1, 0,
|
||||
Audio->AttenuationSettings, nullptr, GetOwner());
|
||||
}
|
||||
else
|
||||
{
|
||||
Audio->Play();
|
||||
}
|
||||
}
|
||||
|
||||
soundHasBeenPlayed = true;
|
||||
GetWorld()->GetTimerManager().SetTimer(handle, [this, TargetRotation]() {
|
||||
Move(TargetRotation);
|
||||
}, RotationDelay, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void URotatingActor::Rotate()
|
||||
@ -70,4 +53,37 @@ void URotatingActor::Rotate()
|
||||
FRotator rotation = GetOwner()->GetActorRotation();
|
||||
rotation.Yaw = TargetAngle;
|
||||
Rotate(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
void URotatingActor::Move(const FRotator TargetRotation)
|
||||
{
|
||||
this->targetRotation = TargetRotation;
|
||||
rotating = true;
|
||||
tempRotation = (TargetRotation.Yaw < 0) ? -1.f : 1.f;
|
||||
if (Negative)
|
||||
{
|
||||
tempRotation = (TargetRotation.Yaw < 0) ? 1.f : -1.f;
|
||||
}
|
||||
|
||||
TArray<UAudioComponent*> Audios;
|
||||
GetOwner()->GetComponents<UAudioComponent>(Audios);
|
||||
|
||||
if (Audios.Num() == 0) return;
|
||||
if (soundHasBeenPlayed) return;
|
||||
|
||||
for (auto Audio : Audios)
|
||||
{
|
||||
if (Audio->ComponentHasTag("location"))
|
||||
{
|
||||
UGameplayStatics::PlaySoundAtLocation(GetOwner(), Audio->Sound, GetOwner()->GetActorLocation(),
|
||||
GetOwner()->GetActorRotation(), 1, 1, 0,
|
||||
Audio->AttenuationSettings, nullptr, GetOwner());
|
||||
}
|
||||
else
|
||||
{
|
||||
Audio->Play();
|
||||
}
|
||||
}
|
||||
|
||||
soundHasBeenPlayed = true;
|
||||
}
|
@ -34,7 +34,7 @@ public:
|
||||
float RotationSpeed = 15.f;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
float RotationDelay = 2.f;
|
||||
float RotationDelay = 0.f;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
bool Negative = false;
|
||||
@ -44,4 +44,5 @@ private:
|
||||
bool rotating;
|
||||
bool soundHasBeenPlayed;
|
||||
float tempRotation;
|
||||
void Move(FRotator TargetRotation);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user