命名为BonusBoxArea
头文件
添加
#include "UdpProj_0816/UdpProj_0816Character.h"
public:
区域添加如下代码
// Actor Enter
virtual void NotifyActorBeginOverlap(AActor* OtherActor) override;
// Actor Exit
virtual void NotifyActorEndOverlap(AActor* OtherActor) override;
其中,NotifyActorBeginOverlap
类似Unity中的OnTriggerEnter
;NotifyActorEndOverlap
相当于Unity中的OnTriggerExit
底部
添加如下代码
void ABonusBoxArea::NotifyActorBeginOverlap(AActor* OtherActor)
{
}
void ABonusBoxArea::NotifyActorEndOverlap(AActor* OtherActor)
{
}
类似于Unity,需要判断物体的Tags或者物体的Name来判断进入的Actor是不是我们想要的,因此,需要在cpp中丰富我们的代码:
void ABonusBoxArea::NotifyActorBeginOverlap(AActor* OtherActor)
{
auto hubActor = Cast<ACharacter>(OtherActor);
if (hubActor != nullptr)
{
UE_LOG(LogTemp,Warning, TEXT("Character Enter"));
}
}
void ABonusBoxArea::NotifyActorEndOverlap(AActor* OtherActor)
{
auto hubActor = Cast<ACharacter>(OtherActor);
if (hubActor != nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("Character Exit"));
}
}
命名为 NetBox
控制玩家移动至Box区域,可以看到结果: