diff --git a/Content/Audio/Sound/345684__provan9__radio-alert.uasset b/Content/Audio/Sound/345684__provan9__radio-alert.uasset new file mode 100644 index 0000000..e26e48a Binary files /dev/null and b/Content/Audio/Sound/345684__provan9__radio-alert.uasset differ diff --git a/Content/Levels/FactoryHall.umap b/Content/Levels/FactoryHall.umap index bfadd6d..ba5fd14 100644 Binary files a/Content/Levels/FactoryHall.umap and b/Content/Levels/FactoryHall.umap differ diff --git a/Content/Levels/FactoryHall_BuiltData.uasset b/Content/Levels/FactoryHall_BuiltData.uasset index 7a2e8e6..bd81655 100644 Binary files a/Content/Levels/FactoryHall_BuiltData.uasset and b/Content/Levels/FactoryHall_BuiltData.uasset differ diff --git a/Source/BuildingEscape/RotatingActor.cpp b/Source/BuildingEscape/RotatingActor.cpp index d013f8b..0479d74 100644 --- a/Source/BuildingEscape/RotatingActor.cpp +++ b/Source/BuildingEscape/RotatingActor.cpp @@ -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 Audios; - GetOwner()->GetComponents(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); -} \ No newline at end of file +} + +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 Audios; + GetOwner()->GetComponents(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; +} \ No newline at end of file diff --git a/Source/BuildingEscape/RotatingActor.h b/Source/BuildingEscape/RotatingActor.h index 31f322e..0420ea0 100644 --- a/Source/BuildingEscape/RotatingActor.h +++ b/Source/BuildingEscape/RotatingActor.h @@ -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); };