ReadMe.md
游戏控制的摄像机
了解如何激活和切换不同的视角。
定义引用的Actor
UPROPERTY(EditAnywhere)
AActor* CameraOne;
UPROPERTY(EditAnywhere)
AActor* CameraTwo;
float TimeToNextCameraChange;
切换视角
#include "Kismet/GameplayStatics.h"
void ACameraDirector::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
const float TimeBetweenCameraChanges = 2.0f;
const float SmoothBlendTime = 0.75f;
TimeToNextCameraChange -= DeltaTime;
if (TimeToNextCameraChange <= 0.0f) {
TimeToNextCameraChange += TimeBetweenCameraChanges;
APlayerController* PlayController = UGameplayStatics::GetPlayerController(this, 0);
if (PlayController) {
if (PlayController->GetViewTarget() != CameraOne && CameraOne != nullptr) {
PlayController->SetViewTarget(CameraOne);
}
else if (PlayController->GetViewTarget() != CameraTwo && CameraTwo != nullptr) {
PlayController->SetViewTargetWithBlend(CameraTwo, SmoothBlendTime);
}
}
}
}