请选择 进入手机版 | 继续访问电脑版

01BIM社区

 找回密码
 立即注册

扫一扫,访问微社区

查看: 6350|回复: 3

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

[复制链接]

155

主题

643

帖子

2531

积分

金牌会员

Rank: 6Rank: 6

积分
2531
发表于 2018-3-27 09:37:44 | 显示全部楼层 |阅读模式
官方案例程序《Variables, Timers, and Events》的错误
一、缺包含文件:
#include "Runtime/Engine/Classes/Components/TextRenderComponent.h"
二、包含文件的位置:
应放在#include "Countdown.generated.h"之前!

16.jpg
回复

使用道具 举报

155

主题

643

帖子

2531

积分

金牌会员

Rank: 6Rank: 6

积分
2531
 楼主| 发表于 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;
};



回复 支持 反对

使用道具 举报

155

主题

643

帖子

2531

积分

金牌会员

Rank: 6Rank: 6

积分
2531
 楼主| 发表于 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!"));
}


回复 支持 反对

使用道具 举报

155

主题

643

帖子

2531

积分

金牌会员

Rank: 6Rank: 6

积分
2531
 楼主| 发表于 2018-3-27 18:31:21 | 显示全部楼层
在蓝图中显现属性和事件
17.jpg
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|01BIM社区 - 最专业的BIM技术交流平台 ( 渝ICP备15000873号 )

GMT+8, 2024-3-29 15:39 , Processed in 0.066126 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表