【问题标题】:how to use the StartCoroutine method如何使用 StartCoroutine 方法
【发布时间】: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); }

标签: c# unity3d


【解决方案1】:

你应该在参数-StartCoroutine(nameof(PowerupCountdownRoutine))中写nameof(@name of the method@)

【讨论】:

  • 非常感谢,成功了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-05
  • 2016-08-19
  • 1970-01-01
  • 2018-06-20
  • 2015-09-16
  • 2020-07-13
相关资源
最近更新 更多