【发布时间】:2022-11-12 10:36:24
【问题描述】:
我曾尝试在 IEnumerator 方法上使用 StartCoroutine,但它不起作用。
它一直说该方法不能变成字符串,但我不想把它变成字符串。这是我的代码:
StartCoroutine(PowerupCountdownRoutine());
IEnumerator PowerupCountdownRoutine()
{
yield return new WaitForSeconds(7);
hasPowerup = false
}
【问题讨论】:
-
你能告诉我们你得到的错误吗?
-
您应该显示错误和整个脚本。它可能涉及我们看不到的脚本的另一个区域。
-
错误是:无法从“方法组”转换为“字符串”
-
除了您在 hasPowerup = false 处缺少分号这一事实之外,您的代码还会运行。如果你想要一个答案,你将不得不提供更多。
-
这是代码的一部分: public bool hasPowerup = false;私人浮动 powerUpStrength = 15.0f;私人无效OnTriggerEnter(对撞机其他){if(other.CompareTag(“PowerUp”)){hasPowerup = true;销毁(other.gameObject); powerupIndicator.gameObject.SetActive(true); StartCoroutine(PowerupCountdownRoutine()); } } IEnumerable PowerupCountdownRoutine() { hasPowerup = false;收益率返回新的 WaitForSeconds(7); powerupIndicator.gameObject.SetActive(false); }