Protptype of a wave based, first person shooter game made in Unreal Engine 4
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
MechDefence/Private/MPlayerController.cpp

69 lines
1.4 KiB

// Fill out your copyright notice in the Description page of Project Settings.
#include "MPlayerController.h"
#include "Blueprint/UserWidget.h"
#include "MWeapon.h"
AMPlayerController::AMPlayerController()
{
bShouldPerformFullTickWhenPaused = true;
}
void AMPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("Pause", IE_Pressed, this, &AMPlayerController::TogglePause);
}
void AMPlayerController::TogglePause()
{
//SetPause(IsPaused() ? false : true);
UE_LOG(LogTemp, Log, TEXT("Pause"));
Pause();
APawn* ControlledPawn = GetPawn();
if(IsPaused())
{
ControlledPawn->DisableInput(this);
if(PauseWidget)
PauseWidget->AddToViewport();
if(HudWidget)
HudWidget->RemoveFromViewport();
FInputModeGameAndUI InputMode;
SetInputMode(InputMode);
bShowMouseCursor = true;
}
else
{
ControlledPawn->EnableInput(this);
if(HudWidget)
HudWidget->AddToViewport();
if(PauseWidget)
PauseWidget->RemoveFromViewport();
FInputModeGameOnly InputMode;
SetInputMode(InputMode);
bShowMouseCursor = false;
}
}
void AMPlayerController::BeginPlay()
{
Super::BeginPlay();
if(HudWidgetClass)
{
HudWidget = CreateWidget(this, HudWidgetClass, "PlayerHud");
if(HudWidget)
HudWidget->AddToViewport();
}
if(PauseWidgetClass)
{
PauseWidget = CreateWidget(this, PauseWidgetClass, "PauseWidget");
}
}