Need A AutoLevel Generated Script For Mario Game

Need A Mario Game AutoLevel Generator Script in which my scenario is like i have boundaries in X-axis And Y-axis like -1.31 to 355.4 in X-axis and 1.41 to 6.79 in Y-axis i want the level is created is in these boundaries.

After this i have 4 type of prefabs 3 are ground prefab or 1 is water prefab the ground prefab is walkable and water prefab is not walkable. One of the ground prefab is always above the water prefab with some distance like 3.5f and I don’t want that any prefab get Merge with another or any prefab get stuck in another prefab.

the ratio of water tiles and ground tiles is 35 - 65 but the ratio of 3 Ground Tiles is 25 20 20

my ‘first tile’ is always a ‘ground tile’ on which my player prefab is standing on it and ‘last 12 tiles’ are also the ‘ground tile’

using UnityEngine;

public class LevelGenerator : MonoBehaviour
{
    public GameObject[] groundTilesType1;
    public GameObject[] groundTilesType2;
    public GameObject[] waterTiles;
    public GameObject playerPrefab;

    public float startX = -1.31f;
    public float endX = 355.4f;
    public float minY = 1.41f;
    public float maxY = 6.78f;
    public float distanceAboveWater = 3.5f;
    public float fixedGap = 2f;

    void Start()
    {
        GenerateLevel();
    }

    void GenerateLevel()
    {
        float levelLength = endX - startX;
        Vector3 currentPosition = new Vector3(startX, minY, 0);

        
        GameObject firstGroundTile = GetRandomGroundType1Prefab();
        Instantiate(firstGroundTile, currentPosition, Quaternion.identity);

                Vector3 playerSpawnPosition = new Vector3(0, 6, 0);
        Instantiate(playerPrefab, playerSpawnPosition, Quaternion.identity);

        currentPosition += Vector3.right * fixedGap;

        for (float i = startX + 2 * fixedGap; i < endX - 8 * fixedGap; i += fixedGap)
        {
            GameObject tilePrefab;

            
            float randomValue = Random.Range(0f, 1f);
            if (randomValue < 0.65f)
            {
                tilePrefab = GetRandomGroundType1Prefab();
            }
            else
            {
                tilePrefab = GetRandomWaterPrefab();

                
                currentPosition = MoveToNextPosition(currentPosition, fixedGap);
                Instantiate(GetRandomGroundType2Prefab(), currentPosition + new Vector3(0, distanceAboveWater, 0), Quaternion.identity);
            }

            currentPosition = MoveToNextPosition(currentPosition, fixedGap);
            Instantiate(tilePrefab, currentPosition, Quaternion.identity);
        }

        
        for (float i = 0; i < 12; i++)
        {
            GameObject groundPrefab = GetRandomGroundType1Prefab();
            currentPosition = MoveToNextPosition(currentPosition, fixedGap);
            Instantiate(groundPrefab, currentPosition, Quaternion.identity);
        }
    }

    Vector3 MoveToNextPosition(Vector3 currentPosition, float gap)
    {
        return currentPosition + Vector3.right * gap;
    }

    GameObject GetRandomGroundType1Prefab()
    {
        int randomIndex = Random.Range(0, groundTilesType1.Length);
        return groundTilesType1[randomIndex];
    }

    GameObject GetRandomGroundType2Prefab()
    {
        int randomIndex = Random.Range(0, groundTilesType2.Length);
        return groundTilesType2[randomIndex];
    }

    GameObject GetRandomWaterPrefab()
    {
        int randomIndex = Random.Range(0, waterTiles.Length);
        return waterTiles[randomIndex];
    }
}

recently I am using this script but it has many issues like on above the water tile it make ground tile at a distance of 3.5f but I need that the above the water tiles the there is ground tile which height is start from above of 3.5f of water tile and goes to 6.79f I need the ground tile above the water tile is between 3.5 to 6.79 in between it the water tiles are always at minimum height like 1.41 on y-Axis.

@Marcus1235, I’m struggling to figure out what your actual issue is and what you want to accomplish. could you maybe reformulate the question?

As far as I do understand your question, splitting your code over two or three different script components, could solve your issue regarding the ground and water prefabs not doing what you want them to do. instead of making one complex script, make multiple simple scripts and combine these to get the result you want. Then again, I may be completely misunderstanding your question, so please take this advice with a healthy dose of skepticism in mind.