Fabrik: Beleuchtung & fertiges Gameplay ;Türen jetzt auch mit Verzögerung

This commit is contained in:
Johannes Theiner 2021-03-10 19:26:23 +01:00
parent d0e3953ea7
commit bb34cad8e7
Signed by: joethei
GPG Key ID: 9D2B9A00FDA85BCD
5 changed files with 47 additions and 30 deletions

Binary file not shown.

View File

@ -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;
}

View File

@ -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);
};