美文网首页
18 - Setting Up the Play States

18 - Setting Up the Play States

作者: 镜月s | 来源:发表于2017-09-19 15:37 被阅读15次

    在BatteryCollectorGameMode.h 中添加enum 表示游戏状态 和视频中有一些不同 需要设置类型uint8 否则编译不过

    UENUM(BlueprintType)
    enum class EBatteryPlayState:uint8
    {
    EPlaying,
    EGameOver,
    EWon,
    EUnknown
    };

    在BatteryCollectorGameMode类中添加变量CurrentState 以及相应的Get Set函数

    private:

    EBatteryPlayState CurrentState;
    

    public:
    UFUNCTION(BlueprintPure, Category = "Power")
    EBatteryPlayState GetCurrentState() const;
    UFUNCTION(BlueprintCallable, Category = "Power")
    void SetCurrentState(EBatteryPlayState state);

    编辑Mode类的Tick函数 根据当前的Power 进行逻辑判断 设置相应的状态
    void ABatteryCollectorGameMode::Tick(float DeltaSeconds)
    {
    Super::Tick(DeltaSeconds);
    ABatteryCollectorCharacter* MyCharacter = Cast<ABatteryCollectorCharacter>(UGameplayStatics::GetPlayerPawn(this, 0));
    if (MyCharacter)
    {
    if (MyCharacter->GetCurrentPower() > PowerToWin)
    SetCurrentState(EBatteryPlayState::EWon);
    else if (MyCharacter->GetCurrentPower() > 0)
    {
    MyCharacter->UpdatePower(-DeltaSecondsDecayRate(MyCharacter->GetInitialPower()));
    }
    else
    {
    SetCurrentState(EBatteryPlayState::EGameOver);
    }
    }
    }

    EBatteryPlayState ABatteryCollectorGameMode::GetCurrentState() const
    {
    return CurrentState;
    }

    void ABatteryCollectorGameMode::SetCurrentState(EBatteryPlayState state)
    {
    CurrentState = state;
    }

    编辑Widget 蓝图 添加文本框 并绑定问题内容 给句GameMode中的State输出相应的文本

    Paste_Image.png Paste_Image.png

    相关文章

      网友评论

          本文标题:18 - Setting Up the Play States

          本文链接:https://www.haomeiwen.com/subject/ziwwsxtx.html