Produktion_Digitaler_Medien/Source/BuildingEscape/TriggerOpenDoor.cpp

60 lines
1.5 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());
}
2020-12-01 18:30:41 +01:00
if(!TriggerVolume)
{
UE_LOG(LogTemp, Error, TEXT("No trigger volume found on: %s !"), *GetOwner()->GetName());
}
2020-12-01 11:32:20 +01:00
}
void UTriggerOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (!doorOpen)
{
2020-12-01 18:30:41 +01:00
if(!TriggerVolume)
{
return;
}
2020-12-01 11:32:20 +01:00
TArray<AActor*> overlappingActors;
TriggerVolume->GetOverlappingActors(overlappingActors);
if (overlappingActors.Num() >= 1)
{
2020-12-01 18:30:41 +01:00
if (AudioComponent)
2020-12-01 11:32:20 +01:00
{
AudioComponent->Play();
}
doorOpen = true;
opening = true;
currentRotation = GetOwner()->GetActorRotation();
}
}
if (opening)
{
if (GetOwner()->GetActorRotation().Equals(TargetRotation, 1.0))
{
opening = false;
}
else
{
2020-12-01 18:30:41 +01:00
GetOwner()->AddActorLocalRotation(DeltaTime * TargetSpeed);
2020-12-01 11:32:20 +01:00
}
}
}