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

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

View File

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

View File

@ -26,4 +26,8 @@ private:
UPROPERTY()
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);
};