【发布时间】:2021-07-18 21:28:02
【问题描述】:
我制作了一个脚本,允许在 2 秒后提高玩家的耐力值。我的代码在没有 WaitForSeconds 的情况下完美运行,但突然间耐力的提升立即完成,这不是我想要的。所以我添加了 WaitForSeconds 但没有任何帮助,它不起作用。
if (Input.GetKey(KeyCode.LeftShift))
{
currentstamina -= 1f;
if(currentstamina <= 0)
{
currentstamina = 0;
runningSpeed = walkingSpeed;
}
}
else if (Input.GetKey(KeyCode.LeftShift) == false)
{
if (currentstamina < 20)
{
if (regen != null)
StopCoroutine(regen);
regen = StartCoroutine(StaminaBack());
}
}
IEnumerator StaminaBack()
{
yield return new WaitForSeconds(2f);
while(currentstamina < startingstamina)
{
currentstamina += startingstamina / 100;
yield return regenTick;
}
regen = null;
}
提前感谢您为我提供的帮助。
【问题讨论】:
标签: unity3d