在团结我如何阻止数学永久声明?

0

的问题

问题是简单但是我不能为了我的生活,图。

我的逻辑是这样的

// Static floats are StatBase.maxHealth = 0 and rStat.maxHealth = 70

class rStat : Monobehaviour
{

    
    public bool nomatter = false;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            nomatter = true;
        }


        if (nomatter == true)
        {
            healthcalc();
        }

        void healthcalc()
        {
         StatBase.maxHealth += rstat.maxHealth; // StatBase.maxHealth should = 70 but the 
                                                // number never stops adding

         nomatter = false;

        }
    }
}
c# if-statement static unity3d
2021-11-24 04:05:05
1

最好的答案

0

说实话,逻辑相当奇怪。

为什么有这个 bool 标记如果你已经 一个你想要行动? 你可以简单地做

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        healthcalc();
    }
}

// in general rather put this on class level and don't nest it under Update
void healthcalc()
{
     StatBase.maxHealth += rstat.maxHealth; 
}

或者,如果只有一个线甚至无论如何

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        StatBase.maxHealth += rstat.maxHealth;
    }
}
2021-11-24 08:08:45

鼠标点击的一部分未被实际逻辑。 在游戏玩家将按一下按钮就像"接受"分配一个统计数据点,然后将增加,统计数额。 我的问题是,它正在更新方法,所以它没有什么问题我是这样做将始终只是以积极加入。 谢谢你的回答,虽然我更好的帮助。
joe pace

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................