502
1.在头文件中声明一个摄像机组件:
public:
UPROPERTY(VisibleAnywhere,Category="My Pawn Components")
//class告诉编译器不要对下面的声明提示报错,后面会进行声明
class UCameraComponent* MyCamera;
2.在源文件中包含头文件:
#include "Camera/UCameraComponent.h"
3.在源文件中初始化:
MyCamera=CreateDefaultSubobject<UCameraComponent>(TEXT("MyCamera"));
MyCamera->SetupAttachment(this->GetRootComponent());
MyCamera->SetRelativeLocation(FVector(-300.0f,0.0f,300.0f));
MyCamera->SetRelativeRotation(FRotator(-45.0f,0.0f,0.0f));
4.创建蓝图类BP_MyPawn继承自定义C++类MyPawn
5.在蓝图类中添加网格体模型并赋予材质