Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "PongGameplayController.h"
- #include "Kismet/GameplayStatics.h"
- #include "Net/UnrealNetwork.h"
- #include "PongCamera.h"
- #include "PongRacket.h"
- APongGameplayController::APongGameplayController(const FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- bReplicates = true;
- bAutoManageActiveCameraTarget = false;
- }
- void APongGameplayController::BeginPlay()
- {
- Super::BeginPlay();
- SetInputMode(FInputModeGameOnly());
- APongRacket* ControlledPawn = GetPawn<APongRacket>();
- ControlledPawn != nullptr ?
- GEngine->AddOnScreenDebugMessage(
- -1,
- 10.f,
- FColor::Cyan,
- FString::Printf(
- TEXT("Is controlling a %s pawn."),
- *ControlledPawn->GetClass()->GetDescription()
- )
- ) : GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Cyan, TEXT("No pawn controlled."));
- if (GetLocalRole() == ROLE_Authority)
- {
- APongCamera* MainCamera = Cast<APongCamera>(
- UGameplayStatics::GetActorOfClass(GetWorld(), APongCamera::StaticClass())
- );
- if(MainCamera)
- {
- ViewTarget = MainCamera;
- OnRep_ViewTarget();
- }
- }
- }
- void APongGameplayController::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
- {
- Super::GetLifetimeReplicatedProps(OutLifetimeProps);
- DOREPLIFETIME(APongGameplayController, ViewTarget);
- }
- void APongGameplayController::OnRep_ViewTarget()
- {
- GEngine->AddOnScreenDebugMessage(
- -1,
- 10.f,
- FColor::Green,
- TEXT("Player's point of view changed.")
- );
- SetViewTarget(ViewTarget);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement