首先需要一个C++类(Actor类型就可以)(PickUpBase) 作为所有可拾取物品的根
h:
#include "Components/StaticMeshComponent.h" //组件
#include "Components/SphereComponent.h" //可碰撞
UPROPERTY(VisibleAnywhere,Category="Components")
UStaticMeshComponent* MeshComponent = nullptr; //显示样子
UPROPERTY(VisibleAnywhere, Category = "Components")
USphereComponent* CollisionArea = nullptr; //作用范围区域
UFUNCTION() //绑定此事件 碰到的时候就会执行
void OnOverLap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
virtual void UseItem(AActor* User);
cpp:
APickUpBase::APickUpBase()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTic