Files
BladeSmith/Source/BladeSmith/BladeSmithPickUpComponent.cpp
T
2025-06-19 00:37:06 +08:00

32 lines
983 B
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "BladeSmithPickUpComponent.h"
UBladeSmithPickUpComponent::UBladeSmithPickUpComponent()
{
// Setup the Sphere Collision
SphereRadius = 32.f;
}
void UBladeSmithPickUpComponent::BeginPlay()
{
Super::BeginPlay();
// Register our Overlap Event
OnComponentBeginOverlap.AddDynamic(this, &UBladeSmithPickUpComponent::OnSphereBeginOverlap);
}
void UBladeSmithPickUpComponent::OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
// Checking if it is a First Person Character overlapping
ABladeSmithCharacter* Character = Cast<ABladeSmithCharacter>(OtherActor);
if(Character != nullptr)
{
// Notify that the actor is being picked up
OnPickUp.Broadcast(Character);
// Unregister from the Overlap Event so it is no longer triggered
OnComponentBeginOverlap.RemoveAll(this);
}
}