获取摄像机,摄像机切换Learn Unreal Engine (with C++)
生活随笔
收集整理的這篇文章主要介紹了
获取摄像机,摄像机切换Learn Unreal Engine (with C++)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
攝像機應該是使用最普遍的組件了
獲取攝像機,攝像機切換
新建C++類(以CameraActor為父類)
將攝像機在地圖中放置
頭文件聲明
virtual void BeginPlay() override;UPROPERTY(EditAnywhere, BlueprintReadWrite)UBoxComponent* OverlapVolume; // 盒體組件,用于檢測人物碰撞UPROPERTY(EditAnywhere, BlueprintReadWrite)TSubclassOf<ACameraActor> CameraToFind; //待尋找的攝像機UPROPERTY(EditAnywhere, BlueprintReadWrite)float CameraBlendTime; // 切換時間virtual void NotifyActorBeginOverlap(AActor* OtherActor) override;virtual void NotifyActorEndOverlap(AActor* OtherActor) override;實現
void ABlendTriggerVolume::NotifyActorBeginOverlap(AActor* OtherActor) {Super::NotifyActorBeginOverlap(OtherActor);//如果是人物轉換就能成功,反之nullptrif(AStaticCameraCharacter* PlayerCharacterCheck = Cast<AStaticCameraCharacter>(OtherActor)){//得到玩家角色的玩家控制器,同上if(APlayerController* PlayerCharacterController = Cast<APlayerController>(PlayerCharacterCheck->GetController())){TArray<AActor*> FoundActors;//獲取所有對象的數組UGameplayStatics::GetAllActorsOfClass(GetWorld(), CameraToFind, FoundActors);//攝像機綁定PlayerCharacterController->SetViewTargetWithBlend(FoundActors[0], CameraBlendTime, EViewTargetBlendFunction::VTBlend_Linear);}} } void ABlendTriggerVolume::NotifyActorEndOverlap(AActor* OtherActor) {Super::NotifyActorEndOverlap(OtherActor);if (AStaticCameraCharacter* PlayerCharacterCheck = Cast<AStaticCameraCharacter>(OtherActor)){if(APlayerController* PlayerCharacterController = Cast<APlayerController>(PlayerCharacterCheck->GetController())){PlayerCharacterController->SetViewTargetWithBlend(PlayerCharacterController->GetPawn(), CameraBlendTime, EViewTargetBlendFunction::VTBlend_Linear);}} }之后我們基于攝像機類創建藍圖類,并設置相關內容
在藍圖細節中找到如下,并設置
總結
以上是生活随笔為你收集整理的获取摄像机,摄像机切换Learn Unreal Engine (with C++)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cmd oracle sys登录_ora
- 下一篇: Linux文本检索命令grep笔记