U4初步使用整理(四)切换相机

相机切换控制
关键方法:

UGameplayStatics::GetPlayerController

SetViewTarget

SetViewTargetWithBlend

u4里PlayerController是一个存在但是隐藏的actor,类似unity中空的gameObject.

    void ACameraDirector::Tick( float DeltaTime )
    {
        Super::Tick( DeltaTime );
        const float TimeBetweenCameraChanges = 2.f;
        const float blendTime = 0.5f;
        TimeCircle -= DeltaTime;
        if (TimeCircle <= 0.f)
        {
            TimeCircle += TimeBetweenCameraChanges;

            APlayerController *playerController = UGameplayStatics::GetPlayerController(this, 0);
            if (playerController)
            {
                if (playerController->GetViewTarget() != camera1 && camera1 != nullptr)
                {
                    //playerController->SetViewTarget(camera1);
                    playerController->SetViewTargetWithBlend(camera1, blendTime);
                }
                else if (playerController->GetViewTarget() != camera2 && camera2 != nullptr)
                {
                    playerController->SetViewTargetWithBlend(camera2, blendTime);
                }
            }
        }
    }

你可能感兴趣的:(U4初步使用整理(四)切换相机)