// 开始移动 private IEnumerator MoveCoroutine(int x, int y, float time) { sweet.X = x; sweet.Y = y; Vector2 startPos = sweet.transform.position; Vector2 endPos = sweet.SetPos(x, y); for (float t = 0; t < time; t += Time.deltaTime) { sweet.transform.position = Vector2.Lerp(startPos, endPos, t / time); yield return(null); } // 纠正位置 sweet.transform.position = endPos; StopCoroutine(moveIenumerator); moveIenumerator = null; }