[英]Error `Async test method must have non-void return type` when upgrading from NUnit 2 to NUnit 3
[英]“Class, struct, or interface method must have a return type” Even when function is set to void
我实质上是在尝试使用Unity 2D的UI库淡化UI对象。 函数fadeIn()启动一个协程FadeCanvasGroup,它使用lerping缓慢更改对象的alpha,以便使其淡入淡出fadeOut();。 函数只是将其反转。 但是,在调用fadeIn()时,我不断抛出“类,结构或接口方法必须具有返回类型”错误,这使我感到困惑,考虑到fadeIn()和fadeOut()都是无效函数。
我已将函数更改为公共和私有,添加和删除了空白,并尝试在没有该函数的情况下启动协程,所有这些都失败了。 同样,当使用Unity的引擎将功能附加到按钮时,它可以正常工作,但是当通过脚本调用时,它将失败。
//The element in question being defined(And later set using the engine)
public CanvasGroup uiElement;
//The coroutine in question
private IEnumerator FadeCanvasGroup(CanvasGroup cg, float start, float end,
float lerpTime = 2f)
{
float timeStartedLerping = Time.time;
float timeSinceStarted = Time.time - timeStartedLerping;
float percentageComplete = timeSinceStarted / lerpTime;
while (true)
{
timeSinceStarted = Time.time - timeStartedLerping;
percentageComplete = timeSinceStarted / lerpTime;
float currentValue = Mathf.Lerp(start, end, percentageComplete);
cg.alpha = currentValue;
if (percentageComplete >= 1)
{
break;
}
yield return null;
}
print("done");
}
//The functions to fade in and out
public void fadeIn()
{
StartCoroutine(FadeCanvasGroup(uiElement, uiElement.alpha, 1));
}
public void fadeOut()
{
StartCoroutine(FadeCanvasGroup(uiElement, uiElement.alpha, 0));
}
fadeIn();
fadeIn(); 在末尾被调用应该只是执行,但是前面描述的错误正在发生。 感谢您抽出宝贵时间希望对此提供帮助的任何人。
如果没有一个好的最小的,可复制的示例 ,就不可能为您提供确切的固定代码。 然而…
Unity3d使用C#的方式,有时错误消息不十分清晰。 但是,您会收到此错误,因为协程方法必须返回IEnumerable
。
有关如何正确执行此操作的说明,请参见Unity3d文档中的“淡入淡出”示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.