源代码
新建Pawn
创建C++类
.h文件
配置变量属性
// 将该变量开放给引擎编辑
UPROPERTY(EditAnywhere)
UStaticMeshComponent* OurVisibleComponent;
.cpp文件
实例化各类对象
// Sets default values
AMyPawn::AMyPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// 设置当前的Pawn由哪个玩家控制
AutoPossessPlayer = EAutoReceiveInput::Player0;
// 创建可附加内容的虚拟根组件
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("One"));
// 创建相机
UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Two"));
// 创建可见对象
OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Three"));
// 将相机附加到根组件,
// 偏移并旋转相机
OurCamera->SetupAttachment(RootComponent);
OurCamera->