UE4官方案例,摄像机切换

头文件

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ChangeCamera.generated.h"

UCLASS()
class CPLUSSTUDY_API AChangeCamera : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AChangeCamera();


protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;
	float TimetoChangeCamera;
	int B = 0;
	
	UPROPERTY(EditAnywhere)
		AActor* CameraOne;
	UPROPERTY(EditAnywhere)
		AActor* CameraTwo;
	UPROPERTY(EditAnywhere)
		TArray<AActor*> CameraS;
};

CPP

// Fill out your copyright notice in the Description page of Project Settings.


#include "ChangeCamera.h"
#include "Kismet/GameplayStatics.h"

// Sets default values
AChangeCamera::AChangeCamera()
{
 	// 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;

}

// Called when the game starts or when spawned
void AChangeCamera::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AChangeCamera::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
    const int A = CameraS.Num();
    const float TimeBetweenCameraChanges = 2.0f;
    const float SmoothBlendTime = 0.75f;
    TimetoChangeCamera -= DeltaTime;
    
    
    if (TimetoChangeCamera <= 0.0f)
    {
        TimetoChangeCamera += TimeBetweenCameraChanges;

        // 查找处理本地玩家控制的actor。
        APlayerController* OurPlayerController = UGameplayStatics::GetPlayerController(this, 0);
        if (OurPlayerController)
        {
            //if ((OurPlayerController->GetViewTarget() != CameraOne) && (CameraOne != nullptr))
            //{
            //    // 立即切换到摄像机1。
            //    OurPlayerController->SetViewTarget(CameraOne);
            //}
            //else if ((OurPlayerController->GetViewTarget() != CameraTwo) && (CameraTwo != nullptr))
            //{
            //    // 平滑地混合到摄像机2。
            //    OurPlayerController->SetViewTargetWithBlend(CameraTwo, SmoothBlendTime);
            //}
            if (B < A)
            {
                OurPlayerController->SetViewTargetWithBlend(CameraS[B], SmoothBlendTime);
                B++;
            }else 
            {
                B = 0;
            }
             
           
        }


    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值