UE5 C++ 定时器 官方案例(二)
一.在上一部分里,我们创造了 一个定时器
接下来我们将 时间参数暴露出来,并增加爆照效果到蓝图
#pragma once#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CountdownActor.generated.h"UCLASS()
class GWXPJ_API ACountdownActor : public AActor
{GENERATED_BODY()public:// Sets default values for this actor's propertiesACountdownActor();class UTextRenderComponent* CountdownText;
protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;void UpdateTimeDisplay();void AdvanceTimer();UFUNCTION(BlueprintNativeEvent)void CountdownHasFinished();public:// Called every framevirtual void Tick(float DeltaTime) override;
protected:UPROPERTY(EditAnywhere)int32 CountdonwTime = 3;FTimerHandle CountTimer;};
同样加上UPROPERTY的UPROPERTY(EditAnywhere),后将变量。后倒计时最后一秒的函数暴露给蓝图,重写
void ACountdownActor::CountdownHasFinished_Implementation()
{CountdownText->SetText(FText::FromString(TEXT("GO")));
}
二、创建蓝图,并把部分变量给蓝图。相当于写了个工具
可自己调节事件

这里还学到个沿用C++ 之前的代码,在那个基础上再加蓝图。右键Event重写事件

这样C++原有的也能用,卧槽涨知识了。

