-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLampTrigger.cpp
More file actions
53 lines (38 loc) · 1.66 KB
/
LampTrigger.cpp
File metadata and controls
53 lines (38 loc) · 1.66 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
50
// Fill out your copyright notice in the Description page of Project Settings.
#include "LampTrigger.h"
// Sets default values
ALampTrigger::ALampTrigger()
{
// 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;
// Init
IsLightTurnOn = false;
// BoxCollision 생성 및 함수 바인딩
BoxCollisionComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
BoxCollisionComponent->OnComponentBeginOverlap.AddDynamic(this, &ALampTrigger::OnOverlapBegin);
BoxCollisionComponent->OnComponentEndOverlap.AddDynamic(this, &ALampTrigger::OnOverlapEnd);
// Lamp Mesh
LampMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Lamp"));
LampMeshComponent->SetupAttachment(RootComponent);
// Lamp Light
LampLightComponent = CreateDefaultSubobject<UPointLightComponent>(TEXT("LampLight"));
LampLightComponent->SetupAttachment(LampMeshComponent);
LampLightComponent->SetVisibility(IsLightTurnOn);
}
// Overlap시 Light on
void ALampTrigger::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
IsLightTurnOn = !IsLightTurnOn;
LampLightComponent->SetVisibility(IsLightTurnOn);
}
// Light Off
void ALampTrigger::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
IsLightTurnOn = !IsLightTurnOn;
LampLightComponent->SetVisibility(IsLightTurnOn);
}
// Called when the game starts or when spawned
void ALampTrigger::BeginPlay()
{
Super::BeginPlay();
}