补给基类、生命补给和弹药补给
2023年10月11日 2024年1月11日
为地板和楼梯添加材质
从ShooterGame导出材质
Content/Environment/Materials
- | |
---|---|
M_FFA_Floor_02_Dark | 地板 |
M_FFA_Wall_04 | 楼梯 |
导出
相关资产
导入到ShootThemUp
创建文件夹 Content/ExternalContent/Pickup
, 保存到此处
设置地板
-
应用材质
-
设置变换
设置楼梯
-
移除楼梯
-
添加楼梯
Place Actors > Geometry > Box
-
设置纹理
-
设置变换
-
设置规格
-
一共四级台阶
按下Option键, 延Z轴拖动台阶; Z方向按80递增, X方向按250递增
创建所需静态网格体和材质
创建材质类
Content/Materials
创建材质, 命名为M_BaseGlow
两个参数: Color和Glow
发光参数默认值设为10
创建材质实例
MI_BlueGlow
MI_GreenGlow
如图
创建静态网格体
新建文件夹 Content/Pickups/StaticMeshes
创建生命补给
-
Place Actors > Geometry > Box
, 添加 -
设置
Details > Brush Settings
, X = 40, Y = 80, Z = 40 -
按下E, 切换到旋转模式
-
按下Option, 绕X轴旋转90渡
-
按下Command, 选中两个笔刷
Brush
,Details > Brush Settings > Create Static Mesh
-
保存到
Content/Pickups/StaticMeshes
, 命名为S_Health -
双击打开, 应用材质
创建弹药补给
-
Place Actors > Geometry > Cylinder
, 添加
设置基准Transform > Location
: X = 1000, Y = 2000, Z = 50
圆柱有三个参数, 高度, 半径和分片 -
按下Option, 向上拖动, 设置参数
-
按下Option, 向上拖动, 设置参数
-
Place Actors > Geometry > Sphere
, 添加
球体有两个参数, 半径和细分 -
按下Command, 选中三个圆柱和球体, 拖动, 二者间隔50
-
选中6个圆柱体, 2个球体,
Details > Brush Settings > Create Static Mesh
-
命名为S_Rockets
-
应用材质
创建补给类
基类 | 上级文件夹 | 属性 | |
---|---|---|---|
STUBasePickup | Actor | Pickups | Public |
STUAmmoPickup | STUBasePickup | ||
STUHealthPickup | STUBasePickup |
-
创建派生类
C++ Classes > ShootThemUp > Public > Pickups > STUBasePickup
-
添加头文件搜索路径
ShootThemUp: ShootThemUp.Build.cs
1PublicIncludePaths.AddRange(new string[] 2{ 3 "ShootThemUp/Public/Player", 4 "ShootThemUp/Public/Components", 5 "ShootThemUp/Public/Dev", 6 "ShootThemUp/Public/Weapon", 7 "ShootThemUp/Public/UI", 8 "ShootThemUp/Public/Animations", 9 "ShootThemUp/Public/Pickups" 10});
补给基类
STUBasePickup
添加碰撞组件
ShootThemUp: Pickups/STUBasePickup.h
protected
1class USphereComponent; 2 3UPROPERTY(VisibleAnywhere) 4USphereComponent *CollisionComponent;
触发重叠事件
ShootThemUp: Pickups/STUBasePickup.cpp
1#include "Components/SphereComponent.h" 2 3DEFINE_LOG_CATEGORY_STATIC(LogBasePickup, All, All); 4 5// Constructor 6CollisionComponent = CreateDefaultSubobject<USphereComponent>("SphereComponent"); 7CollisionComponent->InitSphereRadius(50.0f); 8CollisionComponent->SetCollisionEnabled(ECollisionEnabled::QueryOnly); 9CollisionComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap); 10SetRootComponent(CollisionComponent);
覆写NotifyActorBeginOverlap函数, 发生重叠事件时调用
ShootThemUp: Pickups/STUBasePickup.h
protected
1virtual void NotifyActorBeginOverlap(AActor *OtherActor) override;
重叠后销毁Actor
ShootThemUp: Pickups/STUBasePickup.cpp
1void ASTUBasePickup::NotifyActorBeginOverlap(AActor *OtherActor) 2{ 3 Super::NotifyActorBeginOverlap(OtherActor); 4 UE_LOG(LogBasePickup, Display, TEXT("Pickups was taken")); 5 Destroy(); 6}
创建蓝图类
-
创建基于STUAmmoPickup和STUHealthPickup的蓝图类, 保存到
Content/Pickups
-
为蓝图类添加静态网格体组件, 绑定
Content/Pickups/StaticMeshes
下的静态网格体
弹药补给
生命补给
查看
日志