【发布时间】:2021-11-24 04:05:05
【问题描述】:
这个问题很简单,但我一辈子都想不通。
我的逻辑是这样的
// 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;
}
}
}
【问题讨论】:
-
heathcalc应该在Update之外。 -
@Kiner_shah 这立即奏效,我非常感激。感谢您花时间回答这样一个愚蠢的问题。我仍处于学习的爬行阶段,像这样获得的一点点信息令人愤怒。
-
“数字永远不会停止添加”如何?这段代码看起来每次点击都有效。
-
如果你点击了很多次,maxHealth 值将是 70+70+70+70 ,所以这是你的问题吗?
标签: c# unity3d if-statement static