UE4 GAS 04 -伤害设置

初学GAS,仅用作自己查缺补漏,不想再做时又去找视频
参考教程:
英文原版(联机):Ambience Lee:
https://www.udemy.com/course/introduction-to-unreal-engine-4-ability-system/
中文翻译重置(单机):小明:
https://space.bilibili.com/149146076/channel/detail?cid=127939&ctype=0

一、碰到敌人时给自己推送伤害消息,Target为敌人

在这里插入图片描述

二、在GA中等待发送过来的Damage事件并对击中者设置效果,当动画播放完成或取消后停止StopAbility

在这里插入图片描述
在这里插入图片描述

三、设置击中效果GameplayEffect类

在这里插入图片描述

四、通过绑定变量变化反射来更新血量

4.1、自己创建血量UI并设置更新函数

4.2、c++中override PostGameplayEffectExecute函数进行属性改变检测,顺便进行生命值限制

AttributeSetBase.h

	DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnHealthChanged, float, CurHealth, float, MaxHealth);
	UPROPERTY(BlueprintAssignable)
		FOnHealthChanged OnHealthChanged;

	void PostGameplayEffectExecute(const struct FGameplayEffectModCallbackData& Data) override;

AttributeSetBase.cpp


#include "AttributeSetBase.h"
#include "GameplayEffectExtension.h"
#include "GameplayEffect.h"

UAttributeSetBase::UAttributeSetBase()
	:MaxHealth(100.f),Health(MaxHealth)
{
}

void UAttributeSetBase::PostGameplayEffectExecute(const struct FGameplayEffectModCallbackData& Data)
{
	if (Data.EvaluatedData.Attribute.GetUProperty() == FindFieldChecked<FProperty>(UAttributeSetBase::StaticClass(), GET_MEMBER_NAME_CHECKED(UAttributeSetBase, Health)))
	{

		//生命值限制
		Health.SetCurrentValue(FMath::Clamp(Health.GetCurrentValue(), 0.f, MaxHealth.GetCurrentValue()));
		//生命值变化广播
		OnHealthChanged.Broadcast( Health.GetCurrentValue(),MaxHealth.GetCurrentValue());
		//打印生命值到Log
		UE_LOG(LogTemp, Warning, TEXT("Health is %f"), Health.GetCurrentValue());
	}
}

4.3、蓝图中自行绑定函数、加了死亡逻辑

在这里插入图片描述
这样一个具有简单逻辑的GAS项目就起来了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值