IEnumerator SmoothlyShiftPosition(Vector3 destination, float OverTime) {
float startTime = 0;
while (startTime < OverTime)
{
Debug.Log(startTime/OverTime + "changing: " + navigationCanvas.transform.position);
Debug.Log("startTime : " + startTime);
navigationCanvas.transform.position = Vector3.Lerp(navigationCanvas.transform.position, destination, startTime/OverTime);
startTime += Time.deltaTime * 2f;
yield return null;
}
navigationCanvas.transform.position = destination;
}
我有这个简单的代码片段,我用它来将我的对象轻松地移动到指定的位置,它可以正常工作,但并非总是如此。我记录了不同的数据,发现我的startTime变量连续变为零 。我无法弄清楚为什么会发生这种情况?我做错了什么
我这样称呼我的协程
if (SmoothlyShiftPositionIEum != null) {
StopCoroutine(SmoothlyShiftPositionIEum);
}
SmoothlyShiftPositionIEum = StartCoroutine(SmoothlyShiftPosition(navCanvas, smoothPositionTime));