tzbm123456 发表于 2018-3-27 09:37:44

官方案例程序《Variables, Timers, and Events》的错误

官方案例程序《Variables, Timers, and Events》的错误
一、缺包含文件:
#include "Runtime/Engine/Classes/Components/TextRenderComponent.h"
二、包含文件的位置:
应放在#include "Countdown.generated.h"之前!


tzbm123456 发表于 2018-3-27 09:39:35

本帖最后由 tzbm123456 于 2018-3-27 09:43 编辑

Countdown.h文件内容:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Runtime/Engine/Classes/Components/TextRenderComponent.h"
#include "Countdown.generated.h"
UCLASS()
class HOWTO_VTE_API ACountdown : public AActor
{
      GENERATED_BODY()      
public:      
      // Sets default values for this actor's properties
      ACountdown();
protected:
      // Called when the game starts or when spawned
      virtual void BeginPlay() override;


public:      
      // Called every frame
      virtual void Tick(float DeltaTime) override;
      int32 CountdownTime;
      UTextRenderComponent* CountdownText;
      void UpdateTimerDisplay();
      void AdvanceTimer();
      void CountdownHasFinished();
      FTimerHandle CountdownTimerHandle;
};



tzbm123456 发表于 2018-3-27 09:40:54

本帖最后由 tzbm123456 于 2018-3-27 09:44 编辑

Countdown.cpp文件内容:
// Fill out your copyright notice in the Description page of Project Settings.
#include "Countdown.h"
// Sets default values
ACountdown::ACountdown()
{
         // Set this actor to call Tick() every frame.You can turn this off to improve performance if you don't need it.
      PrimaryActorTick.bCanEverTick = false;
      CountdownText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("CountdownNumber"));
      CountdownText->SetHorizontalAlignment(EHTA_Center);
      CountdownText->SetWorldSize(150.0f);
      RootComponent = CountdownText;
      CountdownTime = 10;
}
// Called when the game starts or when spawned
void ACountdown::BeginPlay()
{
      Super::BeginPlay();
      UpdateTimerDisplay();
      GetWorldTimerManager().SetTimer(CountdownTimerHandle, this, &ACountdown::AdvanceTimer, 1.0f, true);      
}
// Called every frame
void ACountdown::Tick(float DeltaTime)
{
      Super::Tick(DeltaTime);
}
void ACountdown::UpdateTimerDisplay()
{
      CountdownText->SetText(FString::FromInt(FMath::Max(CountdownTime, 0)));
}
void ACountdown::AdvanceTimer()
{
      --CountdownTime;
      UpdateTimerDisplay();
      if (CountdownTime < 1)
      {
                //We're done counting down, so stop running the timer.
                GetWorldTimerManager().ClearTimer(CountdownTimerHandle);
                CountdownHasFinished();
      }
}
void ACountdown::CountdownHasFinished()
{
      //Change to a special readout
      CountdownText->SetText(TEXT("GO!"));
}


tzbm123456 发表于 2018-3-27 18:31:21

在蓝图中显现属性和事件

页: [1]
查看完整版本: 官方案例程序《Variables, Timers, and Events》的错误