1 定义并实现交互接口
接口定义:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "MyInterActInterface.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UMyInterActInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class ARPG_CPLUS_API IMyInterActInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void OnInterAct(APawn* InstigatorPawn);
};
实现接口:
class ARPG_CPLUS_API AInterActTrigger : public AActor,public IMyInterActInterface
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AInterActTrigger();
virtual void OnInterAct_Implementation(APawn* InstigatorPawn)override;
.......
}
实现里绑定碰撞函数,重叠时设置指针:
// Fill out your copyright notice in the Description page of Project Settings.
#include "InterAct/InterActTrigger.h"
#include "Components/BoxComponent.h"
#include "Player/MyPlayer.h"
// Sets default values
AInterActTrigger::AInterActTrigger()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// 创建 BoxCollision 组件
BoxCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
BoxCollision->SetupAttachment(RootComponent); // 绑定到根组件
BoxCollision->S

最低0.47元/天 解锁文章
2935

被折叠的 条评论
为什么被折叠?



