타이머
This commit is contained in:
parent
36891ab3d1
commit
b4912f8f3e
@ -8,12 +8,7 @@
|
|||||||
void ATower::Tick(float DeltaTime)
|
void ATower::Tick(float DeltaTime)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
if (Tank == nullptr)
|
if (InFireRange())
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation());
|
|
||||||
if (Distance <= FireRange)
|
|
||||||
{
|
{
|
||||||
RotateTurret(Tank->GetActorLocation());
|
RotateTurret(Tank->GetActorLocation());
|
||||||
}
|
}
|
||||||
@ -23,4 +18,26 @@ void ATower::BeginPlay()
|
|||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
|
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;
|
||||||
|
}
|
||||||
|
@ -25,5 +25,12 @@ private:
|
|||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Rotate")
|
UPROPERTY(EditAnywhere, Category = "Rotate")
|
||||||
float FireRange = 400;
|
float FireRange = 400;
|
||||||
|
|
||||||
|
FTimerHandle FireRateTimerHandle;
|
||||||
|
float FireRate = 2.0f;
|
||||||
|
|
||||||
|
void CheckFireCondition();
|
||||||
|
|
||||||
|
bool InFireRange();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user