Create AI Guard Class

创建FPSAIGuard类

Create AI Guard Class

不需要玩家输入,删除多余的函数

FPSAIGuard.h

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "FPSAIGuard.generated.h" UCLASS()
class FPSGAME_API AFPSAIGuard : public ACharacter
{
GENERATED_BODY() public:
AFPSAIGuard(); protected:
virtual void BeginPlay() override; public:
virtual void Tick(float DeltaTime) override;
};

FPSAIGuard.cpp

#include "FPSAIGuard.h"

AFPSAIGuard::AFPSAIGuard()
{
PrimaryActorTick.bCanEverTick = true; } void AFPSAIGuard::BeginPlay()
{
Super::BeginPlay(); } void AFPSAIGuard::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

导入角色资源

Create AI Guard Class

创建蓝图继承自FPSAIGuard类

Create AI Guard Class

命名为BP_Guard

Create AI Guard Class

对蓝图类进行初始化,设置网格体组件和动画

在FPSGame.Build.cs添加AI模块

    PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" ,"AIModule"});

在FPSAIGuard.h定义一个人形体感应组件,可用于发现玩家人物并听到为发射物创建的声音

    UPROPERTY(VisibleAnywhere,Category="Components")
UPawnSensingComponent* PawnSensingComp;

前向声明

class UPawnSensingComponent;

在FPSAIGuard.cpp初始化变量

PawnSensingComp = CreateDefaultSubobject<UPawnSensingComponent>(TEXT("PawnSensingComp"));
上一篇:自定义NSLog


下一篇:Linux程序包管理.md