【发布时间】:2016-04-11 03:56:02
【问题描述】:
所以,我正在尝试为我的游戏制作一个“商人”系统。 5 分钟后(计时器正在计时) 商家将可用,第二个计时器将开始计时,但第二个计时器在 -。
void Update()
{
timeremaining -= Time.deltaTime;
int minutes = Mathf.FloorToInt(timeremaining / 60F);
int seconds = Mathf.FloorToInt(timeremaining - minutes * 60);
string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
howlonghere -= Time.deltaTime;
int minutes2 = Mathf.FloorToInt(howlonghere / 60F);
int seconds2 = Mathf.FloorToInt(howlonghere - minutes * 60);
string niceTime2 = string.Format("{0:0}:{1:00}", minutes, seconds);
if (timeremaining > 0)
{
Merchanthuman.enabled = false;
Merchanthuman.interactable = false;
Tiimer.text = "Merchant will be here: " + niceTime;
}
else
{
Tiimer.text = "Merchant is here for: " + niceTime2;
Merchanthuman.enabled = true;
Merchanthuman.interactable = true;
}
}
“商家来这里是为了:”应该开始新的倒计时,这将是第二次。就像 Will be here is 5 分钟 & is here for 2 分钟一样。
【问题讨论】:
-
那么,问题是什么?发生什么了?应该发生什么?
-
另外,看起来deltaTime 不是恒定的,所以
timeremaining当然可以而且很可能最终会是负数。 -
“商家来这里是为了:”应该开始新的倒计时,这将是第二次。就像 Will be here is 5 minutes & is here for is 2 minutes.
-
那么,
howlonghere设置在哪里?即使timereamining是>0,您似乎也在减少howlonghere。所以根据这两者的相对值,当timeremaining达到<=0时,howlonghere可能已经是负数了。 -
注意Unity游戏软件的标签是
unity3d。