forked from Harrison1/unrealcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyTriggerBox.cpp
More file actions
49 lines (43 loc) · 1.56 KB
/
MyTriggerBox.cpp
File metadata and controls
49 lines (43 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Harrison McGuire
// UE4 Version 4.20.2
// https://github.com/Harrison1/unrealcpp
// https://severallevels.io
// https://harrisonmcguire.com
#include "MyTriggerBox.h"
// include draw debu helpers header file
#include "DrawDebugHelpers.h"
AMyTriggerBox::AMyTriggerBox()
{
//Register Events
OnActorBeginOverlap.AddDynamic(this, &AMyTriggerBox::OnOverlapBegin);
OnActorEndOverlap.AddDynamic(this, &AMyTriggerBox::OnOverlapEnd);
}
// Called when the game starts or when spawned
void AMyTriggerBox::BeginPlay()
{
Super::BeginPlay();
DrawDebugBox(GetWorld(), GetActorLocation(), GetComponentsBoundingBox().GetExtent(), FColor::Purple, true, 999, 0, 5);
}
void AMyTriggerBox::OnOverlapBegin(class AActor* OverlappedActor, class AActor* OtherActor)
{
// check if Actors do not equal nullptr and that
if (OtherActor && OtherActor != this)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Green, TEXT("Overlap Begin"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, FString::Printf(TEXT("Overlapped Actor = %s"), *OverlappedActor->GetName()));
}
}
}
void AMyTriggerBox::OnOverlapEnd(class AActor* OverlappedActor, class AActor* OtherActor)
{
if (OtherActor && OtherActor != this)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Green, TEXT("Overlap Ended"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, FString::Printf(TEXT("%s has left the Trigger Box"), *OtherActor->GetName()));
}
}
}