生命补给
2023年10月11日 2024年1月11日
生命补给逻辑
添加属性
ShootThemUp: Pickups/STUHealthPickup.h
protected
1UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "1.0", ClampMax = "100.0")) 2float HealthAmount = 100.0f;
添加接口: 若非死亡跌倒或组件不可寻, 调用健康组件接口
ShootThemUp: Pickups/STUHealthPickup.cpp
1#include "Components/STUHealthComponent.h" 2#include "GameFramework/Pawn.h" 3#include "STUUtils.h" 4 5// GivePickupTo 6 7const auto HealthComponent = STUUtils::GetSTUPlayerComponent<USTUHealthComponent>(PlayerPawn); 8if (!HealthComponent || HealthComponent->IsDead()) return false; 9 10return HealthComponent->TryToAddHealth(HealthAmount);
生命组件逻辑
ShootThemUp: Components/STUHealthComponent.h
public
1bool TryToAddHealth(float HealthAmount); 2bool IsHealthFull() const;
ShootThemUp: Components/STUHealthComponent.cpp
1bool USTUHealthComponent::IsHealthFull() const 2{ 3 return FMath::IsNearlyEqual(Health, MaxHealth); 4} 5 6bool USTUHealthComponent::TryToAddHealth(float HealthAmount) 7{ 8 if (IsHealthFull()) return false; 9 SetHealth(Health + HealthAmount); 10 return true; 11}
修改当前接口调用: 使用IsHealthFull
ShootThemUp: Components/STUHealthComponent.cpp
1// OnTakeAnyDamage 2 3// OnHeal
查看
设置治疗频率
BP_STUBaseCharacter