private IEnumerator AnimateTiles(Vector2[] points, float duration) { if (onAnimationStart != null) { onAnimationStart(this); } // Make sure we disable collisions with the matches tiles endTile.SetColliderEnabled(false); startTile.SetColliderEnabled(false); // Shift the start tile up slightly so it renders above other grid tiles and the line startTile.transform.position += new Vector3(0, 0, -0.2f); if (startTile.gridNode != null) { startTile.gridNode.Clear(); } // Place the line between the depths of start and end _line = LinePoolManager.Instance.PopLine(); SetLinePositions(_line, points, startTile.transform.position.z + 0.1f); for (int i = 0; i < points.Length - 1; i++) { float timer = 0f; // Pre-calculate the division float durationInverse = 1f / duration; while (timer <= 1f) { yield return(null); // Lerp between the two key points in the path based on the timer timer += Time.deltaTime * durationInverse; Vector3 newPos = (Vector3)Vector2.Lerp(points[i], points[i + 1], EaseSineInOut(timer)); newPos.z = startTile.transform.position.z; startTile.transform.position = newPos; } } // Clean up _animationRoutine = null; LinePoolManager.Instance.PushLine(_line); _line = null; // Fire the end event before we destroy ourselves if (onAnimationEnd != null) { onAnimationEnd(this); } // Kill the animation script and tell the tiles to match with each other Destroy(this); SpriteTile.MatchTiles(startTile, endTile); }