D1/Source/D1/AI/HumanoidEnemy.cpp

48 lines
1.5 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "AI/HumanoidEnemy.h"
#include "Blueprint/UserWidget.h"
#include "Components/WidgetComponent.h"
#include "Kismet/GameplayStatics.h"
#include "UI/UI_HealthBar.h"
AHumanoidEnemy::AHumanoidEnemy()
{
TargetingWidgetComponent->SetRelativeLocation(FVector(0.f, 0.f, 132.f));
HealthBarComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("HealthBar"));
static ConstructorHelpers::FClassFinder<UUserWidget> WidgetRef(TEXT("/Game/CombatSystem/UI/WBP_HealthBar.WBP_HealthBar_C"));
if(WidgetRef.Class)
{
HealthBarComponent->SetWidgetClass(WidgetRef.Class);
HealthBarComponent->SetWidgetSpace(EWidgetSpace::Screen);
HealthBarComponent->SetDrawSize({150.f, 10.f});
HealthBarComponent->SetupAttachment(GetMesh());
HealthBarComponent->SetRelativeLocation(FVector(0.f, 0.f, 200.f));
HealthBarComponent->SetVisibility(false);
}
}
void AHumanoidEnemy::BeginPlay()
{
Super::BeginPlay();
if(APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
UUI_HealthBar* HealthBarRef = Cast<UUI_HealthBar>(HealthBarComponent->GetWidget());
if(HealthBarRef) //ExposeOnSpawn 대용으로 사용
{
HealthBarRef->InitializeHealthBar(this->StatsComponent, EStats::Health);
HealthBarComponent->SetWidget(HealthBarRef);
}
}
}
void AHumanoidEnemy::OnTargeted(bool bIsTargeted)
{
Super::OnTargeted(bIsTargeted);
HealthBarComponent->SetVisibility(bIsTargeted);
}