Tower 클래스

This commit is contained in:
강민제 2025-04-25 21:37:57 +09:00
parent 99c89a2ec2
commit 4aabcd0127
3 changed files with 61 additions and 2 deletions

Binary file not shown.

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Tower.h"
#include "Tank.h"
#include "Kismet/GameplayStatics.h"
void ATower::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (Tank)
{
float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation());
if (Distance <= FireRange)
{
RotateTurret(Tank->GetActorLocation());
}
}
}
void ATower::BeginPlay()
{
Super::BeginPlay();
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
}

32
Source/ToonTanks/Tower.h Normal file
View File

@ -0,0 +1,32 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BasePawn.h"
#include "Tower.generated.h"
/**
*
*/
UCLASS()
class TOONTANKS_API ATower : public ABasePawn
{
GENERATED_BODY()
public:
virtual void Tick(float DeltaTime) override;
protected:
virtual void BeginPlay() override;
private:
class ATank* Tank;
UPROPERTY(EditAnywhere, Category = "Rotate")
float FireRange = 400;
};