C/C++教程

UE5/C++ 基于GAS的角色升级 7.3.2 应用击杀敌人获得的经验值奖励

本文主要是介绍UE5/C++ 基于GAS的角色升级 7.3.2 应用击杀敌人获得的经验值奖励,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1

打开FightComponent,HandleHealth中,调用RewardEffect方法

void UFightComponent::HandleHealth(AMMOARPGCharacterBase* InstigatorPawn, AActor* DamageCauser, const struct FGameplayTagContainer& InTags, float InNewValue)
{
	if (MMOARPGCharacterBase.IsValid())
	{
		if (MMOARPGCharacterBase->IsDie())
		{
			//调用RewardEffect方法,应用击杀经验值奖励
			InstigatorPawn->RewardEffect(MMOARPGCharacterBase->GetCharacterLevel(),MMOARPGCharacterBase->GetDeathRewardEffect(), [&]()
				{

				});
            //播放死亡动画
			MMOARPGCharacterBase->PlayDie();
		}
		else
		{
			if (InstigatorPawn)
			{
				if (MMOARPGCharacterBase->GetHitID() != INDEX_NONE)
				{
					//转向攻击者
					FRotator TargetRot = (-InstigatorPawn->GetActorForwardVector()).ToOrientationRotator();
					MMOARPGCharacterBase->SetActorRotation(TargetRot);

					///播放受击
					MMOARPGCharacterBase->PlayHit();
				}
			}
		}
	}
}

RewardEffect方法,应用GE效果到自身

void UFightComponent::RewardEffect(float InNewLevel, TSubclassOf<UGameplayEffect> InNewReward, TFunction<void()> InFun)
{
	if (AbilitySystemComponent.IsValid())
	{
		checkf(InNewReward, TEXT("This value needs to be configured in the blueprint."));

		//应用击杀经验值奖励效果
		AbilitySystemComponent->ApplyGameplayEffectToSelf(Cast<UGameplayEffect>(InNewReward->GetDefaultObject()),InNewLevel, AbilitySystemComponent->MakeEffectContext());

		InFun();
	}
}

这篇关于UE5/C++ 基于GAS的角色升级 7.3.2 应用击杀敌人获得的经验值奖励的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!