// Sets default values
ABlendTriggerVolume::ABlendTriggerVolume()
{
// Set this actor to call Tick() every frame.You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
OverlapVolume = CreateDefaultSubobject<UBoxComponent>(TEXT("CameraProximityVolume"));
OverlapVolume->SetupAttachment(RootComponent);
CameraToFind = CreateDefaultSubobject<ACameraActor>(TEXT("CameraToFind"));
}
//Array to contain found Camera Actors
TArray<AActor*> FoundActors;
//Utility function to populate array with all Camera Actors in the level
UGameplayStatics::GetAllActorsOfClass(GetWorld(), CameraToFind, FoundActors);
//Sets Player Controller view to the first CameraActor found
PlayerCharacterController->SetViewTargetWithBlend(FoundActors[0], CameraBlendTime, EViewTargetBlendFunction::VTBlend_Linear);
削除したコードを以下で置き換えます。
//Sets Player Controller view to the CameraActorToFind variable.
PlayerCharacterController->SetViewTargetWithBlend(CameraToFind, CameraBlendTime, EViewTargetBlendFunction::VTBlend_Linear);
}
}
}
//Copyright 1998-2021 Epic Games, Inc.無断複写・転載を禁じます。
pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "BlendTriggerVolume.generated.h"
UCLASS()
class STATICCAMERAS_API ABlendTriggerVolume : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ABlendTriggerVolume();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UBoxComponent* OverlapVolume;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ACameraActor* CameraToFind;
UPROPERTY(EditDefaultsOnly, meta =(ClampMin = 0.0f))
float CameraBlendTime;
virtual void NotifyActorBeginOverlap(AActor* OtherActor);
virtual void NotifyActorEndOverlap(AActor* OtherActor);
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
BlendTriggerVolume.cpp
//Copyright 1998-2021 Epic Games, Inc.無断複写・転載を禁じます。
#include "BlendTriggerVolume.h"
#include "Components/BoxComponent.h"
#include "StaticCamerasCharacter.h"
#include "Camera/CameraActor.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
// Sets default values
ABlendTriggerVolume::ABlendTriggerVolume()
{
// Set this actor to call Tick() every frame.You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
OverlapVolume = CreateDefaultSubobject<UBoxComponent>(TEXT("CameraProximityVolume"));
OverlapVolume->SetupAttachment(RootComponent);
CameraToFind = CreateDefaultSubobject<ACameraActor>(TEXT("CameraToFind"));
}
// Called when the game starts or when spawned
void ABlendTriggerVolume::BeginPlay()
{
Super::BeginPlay();
}
void ABlendTriggerVolume::NotifyActorBeginOverlap(AActor* OtherActor)
{
if (AStaticCamerasCharacter* PlayerCharacterCheck = Cast<AStaticCamerasCharacter>(OtherActor))
{
if (APlayerController* PlayerCharacterController = Cast<APlayerController>(PlayerCharacterCheck->GetController()))
{
PlayerCharacterController->SetViewTargetWithBlend(CameraToFind, CameraBlendTime, EViewTargetBlendFunction::VTBlend_Linear);
}
}
}
void ABlendTriggerVolume::NotifyActorEndOverlap(AActor* OtherActor)
{
if (AStaticCamerasCharacter* PlayerCharacterCheck = Cast<AStaticCamerasCharacter>(OtherActor))
{
if (APlayerController* PlayerCharacterController = Cast<APlayerController>(PlayerCharacterCheck->GetController()))
{
PlayerCharacterController->SetViewTargetWithBlend(PlayerCharacterController->GetPawn(), CameraBlendTime, EViewTargetBlendFunction::VTBlend_Linear);
}
}
}
// Called every frame
void ABlendTriggerVolume::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}