【UE4】【C++】游戏中可拾取物品(捡到之后buff作用、捡完消失)

本文介绍了如何在UE4游戏中使用C++创建可拾取物品系统。通过定义一个基类(PickUpBase)作为所有可拾取物品的父类,并为不同类型的物品创建子类,实现特定的BUFF效果。当玩家拾取物品后,物品会应用相应的BUFF并消失。
摘要由CSDN通过智能技术生成

首先需要一个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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值