1. 新建c++工程
2. 打开world setting
3. 修改默认GamePlay
4. 依次新建对应GamePlay替换默认GamePlay
Default Pawn
UCLASS()
class HELLOGP_API AHelloPawn : public APawn
{
GENERATED_BODY()
}
HUD
UCLASS()
class HELLOGP_API AHelloHUD : public AHUD
{
GENERATED_BODY()
};
PlayerController
UCLASS()
class HELLOGP_API AHelloPlayerController : public APlayerController
{
GENERATED_BODY()
};
GameState
UCLASS()
class HELLOGP_API AHelloGameStateBase : public AGameStateBase
{
GENERATED_BODY()
};
PlayerState
UCLASS()
class HELLOGP_API AHelloPlayerState : public APlayerState
{
GENERATED_BODY()
}
SpectatorPawn
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默认构造函数
#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. 编译看效果