사용자 지정 플레이어 컨트롤러

This commit is contained in:
강민제 2025-05-09 00:08:39 +09:00
parent 0ff8baf48f
commit bf043b91fd
7 changed files with 52 additions and 12 deletions

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,7 @@
#include "Tank.h" #include "Tank.h"
#include "ToonTanksPlayerController.h"
#include "Camera/CameraComponent.h" #include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h" #include "GameFramework/SpringArmComponent.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
@ -37,13 +38,6 @@ void ATank::Tick(float DeltaTime)
false, false,
HitResult HitResult
); );
DrawDebugSphere(
GetWorld(),
HitResult.ImpactPoint,
25,
12,
FColor::Green
);
RotateTurret(HitResult.ImpactPoint); RotateTurret(HitResult.ImpactPoint);
} }
} }

View File

@ -3,6 +3,7 @@
#include "ToonTanksGameMode.h" #include "ToonTanksGameMode.h"
#include "Tank.h" #include "Tank.h"
#include "ToonTanksPlayerController.h"
#include "Tower.h" #include "Tower.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
@ -10,6 +11,7 @@ void AToonTanksGameMode::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0)); Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
PlayerController = Cast<AToonTanksPlayerController>(UGameplayStatics::GetPlayerController(this, 0));
} }
void AToonTanksGameMode::ActorDied(AActor* DeadActor) void AToonTanksGameMode::ActorDied(AActor* DeadActor)
@ -17,10 +19,9 @@ void AToonTanksGameMode::ActorDied(AActor* DeadActor)
if (DeadActor == Tank) if (DeadActor == Tank)
{ {
Tank->HandleDestruction(); Tank->HandleDestruction();
if (Tank->GetPlayerController()) if (PlayerController)
{ {
Tank->DisableInput(Tank->GetPlayerController()); PlayerController->SetPlayerEnabledState(false);
Tank->GetPlayerController()->bShowMouseCursor = false;
} }
} }
else if (ATower* DestroyedTower = Cast<ATower>(DeadActor)) else if (ATower* DestroyedTower = Cast<ATower>(DeadActor))

View File

@ -25,5 +25,9 @@ private:
// Tank Pointer for DeadActor which is ATank. // Tank Pointer for DeadActor which is ATank.
UPROPERTY() UPROPERTY()
class ATank* Tank; class ATank* Tank;
// ToonTanksPlayerController Pointer of player pawn.
UPROPERTY()
class AToonTanksPlayerController* PlayerController;
}; };

View File

@ -0,0 +1,17 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "ToonTanksPlayerController.h"
void AToonTanksPlayerController::SetPlayerEnabledState(bool bPlayerEnabled)
{
if (bPlayerEnabled)
{
GetPawn()->EnableInput(this);
}
else
{
GetPawn()->DisableInput(this);
}
bShowMouseCursor = bPlayerEnabled;
}

View File

@ -0,0 +1,21 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "ToonTanksPlayerController.generated.h"
/**
*
*/
UCLASS()
class TOONTANKS_API AToonTanksPlayerController : public APlayerController
{
GENERATED_BODY()
public:
// Set this controller to Enabled or Disabled.
void SetPlayerEnabledState(bool bPlayerEnabled);
};