Produktion_Digitaler_Medien/Source/BuildingEscape/TriggerOpenDoor.cpp

54 lines
1.3 KiB
C++
Raw Normal View History

2020-12-01 11:32:20 +01:00
#include "TriggerOpenDoor.h"
UTriggerOpenDoor::UTriggerOpenDoor()
{
PrimaryComponentTick.bCanEverTick = true;
}
void UTriggerOpenDoor::BeginPlay()
{
Super::BeginPlay();
AudioComponent = GetOwner()->FindComponentByClass<UAudioComponent>();
if (!AudioComponent)
{
UE_LOG(LogTemp, Error, TEXT("No audio component found on: %s !"), *GetOwner()->GetName());
}
}
void UTriggerOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (!doorOpen)
{
TArray<AActor*> overlappingActors;
TriggerVolume->GetOverlappingActors(overlappingActors);
if (overlappingActors.Num() >= 1)
{
if (AudioComponent != nullptr)
{
AudioComponent->Play();
}
doorOpen = true;
opening = true;
currentRotation = GetOwner()->GetActorRotation();
}
}
if (opening)
{
if (GetOwner()->GetActorRotation().Equals(TargetRotation, 1.0))
{
UE_LOG(LogTemp, Display, TEXT("Target Rotation reached"))
opening = false;
}
else
{
GetOwner()->AddActorLocalRotation(TargetSpeed);
}
}
}