From 553624bab5c8f195354be0398b7041975ddac1d5 Mon Sep 17 00:00:00 2001 From: 10000Je Date: Thu, 1 May 2025 01:27:30 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B2=B4=EB=A0=A5=20=EC=BB=B4=ED=8F=AC?= =?UTF-8?q?=EB=84=8C=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content/Blueprints/Pawns/BP_PawnTank.uasset | 4 +- Content/Blueprints/Pawns/BP_PawnTurret.uasset | 4 +- Source/ToonTanks/HealthComponent.cpp | 37 +++++++++++++++++ Source/ToonTanks/HealthComponent.h | 40 +++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 Source/ToonTanks/HealthComponent.cpp create mode 100644 Source/ToonTanks/HealthComponent.h diff --git a/Content/Blueprints/Pawns/BP_PawnTank.uasset b/Content/Blueprints/Pawns/BP_PawnTank.uasset index 3f56fc5..4fb7611 100644 --- a/Content/Blueprints/Pawns/BP_PawnTank.uasset +++ b/Content/Blueprints/Pawns/BP_PawnTank.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0dfa34e9e710dc948138b99e70d57b70248d6a9642112f216f9b31a96472416b -size 38048 +oid sha256:fdab66de9b566c666f7ac0675896b3c110c30739362f50ab8e34550b95f66603 +size 39271 diff --git a/Content/Blueprints/Pawns/BP_PawnTurret.uasset b/Content/Blueprints/Pawns/BP_PawnTurret.uasset index fbfa3f3..fb98235 100644 --- a/Content/Blueprints/Pawns/BP_PawnTurret.uasset +++ b/Content/Blueprints/Pawns/BP_PawnTurret.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a6f5bce080339c33c0e9254163b22818b5a2eb8bf0130121a0af213d7412253f -size 34083 +oid sha256:5da67c5292915394a513be1aa9472b90c71ada3b72d74077474f0fb4a5bc7a07 +size 35174 diff --git a/Source/ToonTanks/HealthComponent.cpp b/Source/ToonTanks/HealthComponent.cpp new file mode 100644 index 0000000..3b93742 --- /dev/null +++ b/Source/ToonTanks/HealthComponent.cpp @@ -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")); +} diff --git a/Source/ToonTanks/HealthComponent.h b/Source/ToonTanks/HealthComponent.h new file mode 100644 index 0000000..7a2d980 --- /dev/null +++ b/Source/ToonTanks/HealthComponent.h @@ -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; + + +};