1. 新建c++工程
![image]()
2. 打开world setting
![image]()
3. 修改默认GamePlay
![image]()
4. 依次新建对应GamePlay替换默认GamePlay
![image]()
Default Pawn
![image]()
UCLASS()
class HELLOGP_API AHelloPawn : public APawn
{
GENERATED_BODY()
}
HUD
![image]()
UCLASS()
class HELLOGP_API AHelloHUD : public AHUD
{
GENERATED_BODY()
};
PlayerController
![image]()
UCLASS()
class HELLOGP_API AHelloPlayerController : public APlayerController
{
GENERATED_BODY()
};
GameState
![image]()
UCLASS()
class HELLOGP_API AHelloGameStateBase : public AGameStateBase
{
GENERATED_BODY()
};
PlayerState
![image]()
UCLASS()
class HELLOGP_API AHelloPlayerState : public APlayerState
{
GENERATED_BODY()
}
SpectatorPawn
![image]()
UCLASS()
class HELLOGP_API AHelloSpectatorPawn : public ASpectatorPawn
{
GENERATED_BODY()
};
GameInstance
/** Please add a class description */
UCLASS(Blueprintable, BlueprintType)
class UBP_HelloGameInstance : public UGameInstance
{
GENERATED_BODY()
};
5. 添加AHelloGameModeBase默认构造函数
![image]()
#include "hellogpGameModeBase.h"
#include "HelloGameStateBase.h"
#include "HelloPlayerController.h"
#include "HelloPlayerState.h"
#include "HelloHUD.h"
#include "HelloPawn.h"
#include "HelloSpectatorPawn.h"
AHelloGameModeBase::AHelloGameModeBase()
{
GameStateClass = AHelloGameStateBase::StaticClass();
PlayerControllerClass = AHelloPlayerController::StaticClass();
PlayerStateClass = AHelloPlayerState::StaticClass();
HUDClass = AHelloHUD::StaticClass();
DefaultPawnClass = AHelloPawn::StaticClass();
SpectatorClass = AHelloSpectatorPawn::StaticClass();
}
6. 编译看效果
![image]()