-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHealthComponent.cpp
More file actions
43 lines (34 loc) · 1.32 KB
/
Copy pathHealthComponent.cpp
File metadata and controls
43 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Fill out your copyright notice in the Description page of Project Settings.
#include "HealthComponent.h"
#include "ToonTanksGameMode.h"
#include "Kismet/GameplayStatics.h"
// Sets default values for this component's properties
UHealthComponent::UHealthComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UHealthComponent::BeginPlay()
{
Super::BeginPlay();
Health = MaxHealth;
GetOwner()->OnTakeAnyDamage.AddDynamic(this, &UHealthComponent::DamageTaken);
ToonTanksGameMode = Cast<AToonTanksGameMode>(UGameplayStatics:: GetGameMode(this));
// ...
}
// Called every frame
void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
void UHealthComponent::DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* Instigator, AActor* DamageCauserr) {
if (Damage <= 0.f) return;
Health -= Damage;
if (Health <= 0.f && ToonTanksGameMode) {
ToonTanksGameMode->ActorDied(DamagedActor);
}
}