首先需要一个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.bCanEverTick = true;
CollisionArea = CreateDefaul
UE4 C++实现游戏中的可拾取物品与BUFF系统

本文介绍了如何在UE4游戏中使用C++创建可拾取物品系统。通过定义一个基类(PickUpBase)作为所有可拾取物品的父类,并为不同类型的物品创建子类,实现特定的BUFF效果。当玩家拾取物品后,物品会应用相应的BUFF并消失。
最低0.47元/天 解锁文章
1093

被折叠的 条评论
为什么被折叠?



