UE4 如何通过C++代码切换地图

it2023-10-28  68

//实现代码如下:

/// <summary> /// 切换关卡 /// </summary> /// <param name="LevelName"></param> void AMain::SwitchLevel(FName LevelName) {     UWorld* World = GetWorld();     if (World) {         FString CurrentLevel = World->GetMapName();         FName CurrentLevelName(*CurrentLevel);         if (CurrentLevelName != LevelName) {             UGameplayStatics::OpenLevel(World, LevelName);         }     } }

 

//调用方法如下:

if (OtherActor) {         AMain* Main = Cast<AMain>(OtherActor);         if (Main) {                          Main->SwitchLevel(TransitionLevelName);         }     }

最新回复(0)