c# - Unity Coroutine Yield 似乎每次都关闭协程
问题描述
嘿,所以我一直在研究这种随时间变化的损坏代码,我已经使用了许多在线资源,并且我有大量的尝试迭代,但它没有奏效,所以我来到这里。免责声明:我的对象在屈服时没有被破坏,它只是达到了产量,没有任何反应。
if(CurrentStatus == Status.Burning && burning==false){
burning=true;
StartCoroutine (DamageOverTimeCoroutine(100, 5));
Debug.Log("what");
burning = false;
//CurrentStatus = Status.Empty;
}
public IEnumerator DamageOverTimeCoroutine(float damageAmount, float duration){
float amountDamaged = 0;
float damagePerLoop = damageAmount / duration;
while (amountDamaged < damageAmount) {
int numInt = (int)Math.Ceiling(damagePerLoop);
enemyCurrentHealth -= numInt;
var clone = (GameObject) Instantiate(damageNumber, this.gameObject.transform.position, Quaternion.Euler(Vector3.zero));
clone.GetComponent<FloatingNumbers> ().damageNumber = numInt;
amountDamaged += damagePerLoop;
yield return null;
Debug.Log(amountDamaged);
}
if(amountDamaged>damageAmount){
//StopCoroutine(DamageOverTimeCoroutine());
}
CurrentStatus = Status.Empty;
burning=false;
}
重申一下,它会造成损害,然后在收益回报时退出,我已经将它从 WaitSeconds 更改,只是为了看看它是否可以以任何其他方式工作,它不会。在 yield fire 之后我从来没有调试过。为什么会这样?
将不胜感激,谢谢
解决方案
想通了, var clone = (GameObject) Instantiate(damageNumber, this.gameObject.transform.position, Quaternion.Euler(Vector3.zero)); clone.GetComponent ().damageNumber = numInt;
行简短地循环它而没有引发错误。奇怪,但它现在有效。感谢输入的家伙
推荐阅读
- c - 获取被调用对象不是第 34:13 行的函数或函数指针问题
- asp.net-core-2.1 - 有没有办法在 ASP.NET Core 2.1 中捕获对 Razor 页面不存在的自定义处理程序的 HTTP 请求?
- django - django+uwsgi+docker 同时连接到上游
- tla+ - 如何在 TLA+ 中执行详尽的状态检查?
- python - 使用 Paint per command/function 打开图像
- javascript - 我如何仅通过查看号码来确定国家/地区代码
- angular-cli - Angular cli 7 组件不会在自定义标记调用上呈现 html
- powershell - 比较两个文本文件并将差异写入文本文件
- angular - IF/ELSE IF/ELSE 以 Observable 作为条件
- java - 我的布局在低 dpi 设备上无法正确缩放