public void Pathfinding() { int modC = 1; int maxMod = 100; int threshold = 0; TileClass target = null; Recursion : modC++; for (int mod = 0; mod <= modC; mod++) { if (currentTile.GetTileAt(new Vector2(currentTile.position.x + modC, currentTile.position.y + mod)).priority > threshold) { target = currentTile.GetTileAt(new Vector2(currentTile.position.x + modC, currentTile.position.y + mod)); threshold = target.priority; maxMod = modC * 2; } if (currentTile.GetTileAt(new Vector2(currentTile.position.x + modC, currentTile.position.y - mod)).priority > threshold) { target = currentTile.GetTileAt(new Vector2(currentTile.position.x + modC, currentTile.position.y - mod)); threshold = target.priority; maxMod = modC * 2; } if (currentTile.GetTileAt(new Vector2(currentTile.position.x + mod, currentTile.position.y - modC)).priority > threshold) { target = currentTile.GetTileAt(new Vector2(currentTile.position.x + mod, currentTile.position.y - modC)); threshold = target.priority; maxMod = modC * 2; } if (currentTile.GetTileAt(new Vector2(currentTile.position.x - mod, currentTile.position.y + modC)).priority > threshold) { target = currentTile.GetTileAt(new Vector2(currentTile.position.x - mod, currentTile.position.y + modC)); threshold = target.priority; maxMod = modC * 2; } } if (threshold == currentTile.noOfPriorityLevels || modC == maxMod) { Pathfinding(target); } else { goto Recursion; } }