-
Notifications
You must be signed in to change notification settings - Fork 0
/
VoiceBox.as
50 lines (41 loc) · 1.37 KB
/
VoiceBox.as
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
50
import messagingSystem;
class AVoiceBox : ATriggerBox
{
bool playerIsInside = false;
AMessageDispatcher dispatcher;
UPROPERTY()
USoundCue relevantDialog;
bool hasSentMessage = false;
UFUNCTION(BlueprintOverride)
void BeginPlay()
{
TArray<AMessageDispatcher> messageDispatchers;
GetAllActorsOfClass(messageDispatchers);
ensure(messageDispatchers.Num() > 0, "VoiceBox.as, BeginPlay(): No messagesDispatcher found!");
dispatcher = messageDispatchers[0];
}
UFUNCTION(BlueprintOverride)
void ActorBeginOverlap(AActor OtherActor)
{
if (OtherActor != Gameplay::GetPlayerPawn(0)) return;
playerIsInside = true;
// don't send if relevantDialog is empty or message already has been sent
if(relevantDialog != nullptr || !hasSentMessage) {
//play sound once
Telegram telegram = Telegram(this, Cast<AMessageCharacter>(OtherActor), messegeEnum::VOICELINE, 0, "");
telegram.extraSoundque = relevantDialog;
dispatcher.dispatchMessage(telegram);
hasSentMessage = true;
}
}
UFUNCTION(BlueprintOverride)
void ActorEndOverlap(AActor OtherActor)
{
if (OtherActor != Gameplay::GetPlayerPawn(0)) return;
playerIsInside = false;
}
void destroyItem()
{
this.DestroyActor();
}
}