//Calculates random xy-coordinates of new food. //Checks if food is inside of the borders + not colliding with snake. private Vector2 PossibleRandomXY() { Vector2 xy = new Vector2(0, 0); bool isNotValid = true; while (isNotValid) { LinkedList <Vector2> snakeBodyPositions = snakeMovementScript.getSnakeBodyPosition(); float x = Random.Range(minFoodX, maxFoodX); float y = Random.Range(minFoodY, maxFoodY); xy = new Vector2((int)x + 0.5F, (int)y + 0.5F); if (!snakeBodyPositions.Contains(xy)) { isNotValid = false; } } return(xy); }