10/15/2020
文章目录
添加日志消息
if (GEngine)
{
// 显示调试信息五秒。
// -1"键"值(首个参数)说明我们无需更新或刷新此消息。
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Hello World, this is FPSGameMode!"));
}
- 建议别放在Tick函数中
- 最好用在StartPlay或者BeginPlay函数里面
- GEngine表示游戏引擎,继承于UObject
游戏模式(AGameModeBase)
定义游戏规则:
- 玩家加入游戏的条件,比如初级场,高级场等等
- 游戏暂停和关卡过渡
- 获胜条件
- 等等游戏特定的行为
默认的游戏模式最主要的是分配Classes专栏
- 游戏状态
- 玩家控制器
- HUD 界面
- 默认玩家属性和行为
- 等等
角色类(Pawn)
- Character表示双足站立的人物
- 创建C++类FPSCharacter
- 设置轴映射,即按键操作,WASD表示移动,鼠标左键开火,空格跳跃
- 实现角色移动函数并绑定到移动组件
// 调用后将功能绑定到输入
void AFPSCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// 设置"移动"绑定。
PlayerInputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
}
InputComponent 是定义如何处理输入数据的组件。InputComponent 可附加到需要接收输入的 actor。
BindAxis 和BindAction 绑定了一个委托函数到项目设置中定义的行为或者轴
为什么使用C++还要使用蓝图
因为蓝图可以可视化操作,C++加载一个模型后,并不能直接看到模型的样子,最重要的是模型的初始位置和朝向的调整是很难确定的,同时摄像机的视图也需要仔细调整!
注意事项!
当你对C++的某些Component的属性进行重写的时候,它并不会更新已经生成的蓝图类,比如加入你已经拥有了一个FPSCharacter的蓝图类,现在C++想要隐藏骨骼模型
GetMesh()->SetOwnerNoSee(true)