타이머

This commit is contained in:
강민제 2025-04-28 22:47:50 +09:00
parent 36891ab3d1
commit b4912f8f3e
2 changed files with 31 additions and 7 deletions

View File

@ -8,12 +8,7 @@
void ATower::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (Tank == nullptr)
{
return;
}
float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation());
if (Distance <= FireRange)
if (InFireRange())
{
RotateTurret(Tank->GetActorLocation());
}
@ -23,4 +18,26 @@ void ATower::BeginPlay()
{
Super::BeginPlay();
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &ATower::CheckFireCondition, FireRate, true);
}
void ATower::CheckFireCondition()
{
if (InFireRange())
{
Fire();
}
}
bool ATower::InFireRange()
{
if (Tank)
{
float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation());
if (Distance <= FireRange)
{
return true;
}
}
return false;
}

View File

@ -26,4 +26,11 @@ private:
UPROPERTY(EditAnywhere, Category = "Rotate")
float FireRange = 400;
FTimerHandle FireRateTimerHandle;
float FireRate = 2.0f;
void CheckFireCondition();
bool InFireRange();
};