체력 컴포넌트
This commit is contained in:
parent
69d31cd28a
commit
553624bab5
BIN
Content/Blueprints/Pawns/BP_PawnTank.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/Pawns/BP_PawnTank.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Blueprints/Pawns/BP_PawnTurret.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/Pawns/BP_PawnTurret.uasset
(Stored with Git LFS)
Binary file not shown.
37
Source/ToonTanks/HealthComponent.cpp
Normal file
37
Source/ToonTanks/HealthComponent.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "HealthComponent.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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, AController* Instigator, AActor* DamageCauser)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("Damage Taken"));
|
||||||
|
}
|
40
Source/ToonTanks/HealthComponent.h
Normal file
40
Source/ToonTanks/HealthComponent.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Components/ActorComponent.h"
|
||||||
|
#include "HealthComponent.generated.h"
|
||||||
|
|
||||||
|
|
||||||
|
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
||||||
|
class TOONTANKS_API UHealthComponent : public UActorComponent
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Sets default values for this component's properties
|
||||||
|
UHealthComponent();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Called when the game starts
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Default Max Health
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float MaxHealth = 100.0f;
|
||||||
|
|
||||||
|
// Current Health Value
|
||||||
|
float Health = 0.0f;
|
||||||
|
|
||||||
|
// Function for Damage Event
|
||||||
|
UFUNCTION()
|
||||||
|
void DamageTaken(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* Instigator, AActor* DamageCauser);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Called every frame
|
||||||
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user