UPROPERTY(EditAnyWhere, BlueprintReadOnly)
float Health = 100.0f;
UPROPERTY(EditAnywhere)
float DamageValue = 5.0f;
public:
void DealDamage(float DamageAmount);
Health -= DamageAmount;
if (Health <= 0.0f)
{
Destroy();
}
UFUNCTION()
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& Hit);
UPROPERTY(EditAnywhere)
float DamageValue = 20.0f;
CollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &AProjectile::OnHit);
AEnemy* Enemy = Cast<AEnemy>(OtherActor);
if (Enemy)
{
Enemy->DealDamage(DamageValue);
Destroy();
}
UPROPERTY(EditAnywhere, BlueprintReadOnly)
float Health = 100.0f;
public:
void DealDamage(float DamageAmount);
Health -= DamageAmount;
if (Health <= 0.0f)
{
//restart game
AMonsterShooterGameMode* MyGameMode =
Cast<AMonsterShooterGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
if (MyGameMode)
{
MyGameMode->RestartGameplay(false);
}
Destroy();
}
UFUNCTION()
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& Hit);
UPROPERTY(EditAnywhere)
class UBoxComponent* DamageCollision;
DamageCollision->OnComponentBeginOverlap.AddDynamic(
this, &AEnemy::OnHit);
AMonster_ShooterCharacter* Char =
Cast<AMonster_ShooterCharacter>(OtherActor);
if (Char)
{
Char->DealDamage(DamageValue);
}
UPROPERTY(EditAnywhere)
class UStaticMeshComponent* DoorMesh;
UPROPERTY(EditAnywhere)
class UBoxComponent* CollisionComponent;
// 충돌 발생 시 발동될 함수
UFUNCTION()
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& Hit);
};
DoorMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Door Mesh"));
RootComponent = DoorMesh;
CollisionComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Collision Component"));
CollisionComponent->SetupAttachment(DoorMesh);
CollisionComponent->OnComponentBeginOverlap.AddDynamic(this, &ADoor::OnHit);
void ADoor::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,int32 OtherBodyIndex, bool bFromSweep, const FHitResult& Hit)
{
AMonsterShooterCharacter* Char = Cast<AMonsterShooterCharacter>(OtherActor);
if (Char)
{
AMonsterShooterGameMode* MyGameMode =
Cast<AMonsterShooterGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
if (MyGameMode)
{
MyGameMode->RestartGameplay(true);
}
}
}
: 게임내 HUD, 메뉴, 기타 인터페이스 관련 그래픽요소로 사용자에게 보여주고싶은 것들을 만드는 데 사용할 수 있는 비주얼 UI 제작 툴
Display Player Health 함수를 생성한다.
Monster Shooter Character의 Health 값을 가져온다.
이를 100으로 나누어 백분율로 표현한다.
이를 return 값으로 설정한다. (이때 dangling방지를 위해 유효성을 검사한다.)
health progress bar의 진행상태(percent)를 만들어준 Display Player Health 함수로 설정한다.
만들어둔 Health UI를 BP_Enemy에 추가해준다.
BP_Enemy에서 만들어둔 Enemy Health UI 레퍼런스에서 progress를 들고와 Percent를 Set할 타깃으로 한다.
Enemy의 Health를 100으로 나누어 백분율로 나타내 percent값으로 지정한다.