gpt4 book ai didi

c++ - OnMousePress 脚本在 UE4 中不起作用

转载 作者:行者123 更新时间:2023-11-30 05:01:05 26 4
gpt4 key购买 nike

我想按鼠标左键开门,但是没有任何反应

enter image description here

OpenDoor.h

UCLASS()
class HOME_API ADoorOpen : public APawn
{
GENERATED_BODY()

public:
ADoorOpen();

protected:
virtual void BeginPlay() override;

public:
virtual void Tick(float DeltaTime) override;

virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

UPROPERTY()
USceneComponent* Root;

UPROPERTY(EditAnywhere)
UStaticMeshComponent* Door;

UPROPERTY(EditAnywhere, Category = "DoorOpen")
float rotateValue;

UPROPERTY(BlueprintReadOnly, Category = "DoorOpen")
FRotator doorRotation;

UPROPERTY(BlueprintReadOnly, Category = "DoorOpen")
bool open;

UFUNCTION(BlueprintCallable, Category = "DoorOpen")
void OpenCloseDoor();
};

OpenDoor.cpp

#include "DoorOpen.h"
#include "DrawDebugHelpers.h"
#include "Engine.h"

ADoorOpen::ADoorOpen()
{
PrimaryActorTick.bCanEverTick = true;

rotateValue = 0.0f;
open = false;

Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
RootComponent = Root;

Door = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Door"));
Door->SetRelativeLocation(FVector(0.f, 50.f, -50.f));
Door->SetupAttachment(RootComponent);
}

void ADoorOpen::OpenCloseDoor()
{
// don't see this while playing
GEngine->AddOnScreenDebugMessage(-1, 0.f, FColor::Red, "OpenCloseDoor");
//...
}

void ADoorOpen::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);

// Can't call this
PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &ADoorOpen::OpenCloseDoor);
}

最佳答案

增加AddOnScreenDebugMessage的显示时间

GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, "OpenCloseDoor"); 

否则,文本将只显示一帧。

关于c++ - OnMousePress 脚本在 UE4 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50446440/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com