Advertisement
Guest User

HealthComponent

a guest
Apr 9th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include "Warrior_HealthComponent.h"
  2. #include "..\Public\Warrior_HealthComponent.h"
  3.  
  4. // Sets default values for this component's properties
  5. UWarrior_HealthComponent::UWarrior_HealthComponent()
  6. {
  7.     // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
  8.     // off to improve performance if you don't need them.
  9.     PrimaryComponentTick.bCanEverTick = false;
  10.  
  11.     DefaultHealth = 100;
  12.     Health = DefaultHealth;
  13. }
  14.  
  15.  
  16. // Called when the game starts
  17. void UWarrior_HealthComponent::BeginPlay()
  18. {
  19.     Super::BeginPlay();
  20.  
  21.     AActor* Owner = GetOwner();
  22.     if (Owner)
  23.     {
  24.         Owner->OnTakeAnyDamage.AddDynamic(this, &UWarrior_HealthComponent::TakeDamage);
  25.     }
  26.    
  27. }
  28.  
  29. void UWarrior_HealthComponent::TakeDamage(AActor * DamageActor, float Damage, const UDamageType * damageType, AController * InstigatedBy, AActor * damageCauser)
  30. {  
  31.     if (Damage <= 0)
  32.     {
  33.         return;
  34.     }
  35.     Health = FMath::Clamp(Health - Damage, 0.0f, DefaultHealth);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement