我設了一個 Trigger Box,想說當玩家走進這個空間就顯示提示圖片
目前測試結果,當玩家走進來是沒問題顯示提示圖片沒問題
但問題是當敵人也走進來的時候也會顯示,不知如何修改
判定只有玩家進入才會觸發
///////////////// AManual_Trigger.h /////////////////
#include "CoreMinimal.h"
#include "Engine/TriggerBox.h"
#include "Manual_Trigger.generated.h"
UCLASS()
class ACTGAME_API AManual_Trigger : public ATriggerBox
{
GENERATED_BODY()
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// constructor sets default values for this actor's properties
AManual_Trigger();
// overlap begin function
UFUNCTION()
void OnOverlapBegin(class AActor* OverlappedActor, class AActor* OtherActor);
// overlap end function
UFUNCTION()
void OnOverlapEnd(class AActor* OverlappedActor, class AActor* OtherActor);
// Reference UMG Asset in the Editor
UPROPERTY(EditAnywhere)
TSubclassOf<class UUserWidget> HelpWidgetClass;
// declare widget
class UUserWidget* InfoWidget;
};
///////////////// AManual_Trigger.cpp /////////////////
#include "Manual_Trigger.h"
#include "DrawDebugHelpers.h"
#include "Blueprint/UserWidget.h"
AManual_Trigger::AManual_Trigger()
{
//Register Events
OnActorBeginOverlap.AddDynamic(this, &AManual_Trigger::OnOverlapBegin);
OnActorEndOverlap.AddDynamic(this, &AManual_Trigger::OnOverlapEnd);
}
void AManual_Trigger::BeginPlay()
{
Super::BeginPlay();
DrawDebugBox(GetWorld(), GetActorLocation(), GetActorScale() * 100, FColor::Cyan, true, -1, 0, 5);
}
void AManual_Trigger::OnOverlapBegin(AActor * OverlappedActor, AActor * OtherActor)
{
InfoWidget = CreateWidget<UUserWidget>(GetWorld(), HelpWidgetClass);
if (OtherActor && (OtherActor != this))
{
InfoWidget->AddToViewport();
}
}
void AManual_Trigger::OnOverlapEnd(AActor * OverlappedActor, AActor * OtherActor)
{
if (OtherActor && (OtherActor != this))
{
InfoWidget->RemoveFromViewport();
}
}
|