-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreTrigger.cpp
More file actions
40 lines (32 loc) · 1.16 KB
/
ScoreTrigger.cpp
File metadata and controls
40 lines (32 loc) · 1.16 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
// Fill out your copyright notice in the Description page of Project Settings.
#include "ScoreTrigger.h"
#include "ParaPong_Final.h"
#include "Ball.h"
#include "ParaPongCharacter.h"
#include "ParaPongGameState.h"
#include "Components/BoxComponent.h"
// Sets default values
AScoreTrigger::AScoreTrigger()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
BoxCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("ScoreTrigger"));
BoxCollision->SetGenerateOverlapEvents(true);
BoxCollision->OnComponentBeginOverlap.AddDynamic(this, &AScoreTrigger::OnTriggerBeginOverlap);
SetRootComponent(BoxCollision);
}
void AScoreTrigger::OnTriggerBeginOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult & SweepResult)
{
if(Player && Ball && (OtherActor == Ball))
{
UE_LOG(LogParaPong, Log, TEXT("Ball acertou o gatilho"));
if(AParaPongGameState* GameState = GetWorld()->GetGameState<AParaPongGameState>())
{
GameState->IncrementScore(Player);
}
}
}