Array index is out of range

Currently working on a endless runner / roller or what ever you want to call it.
I’ve made it so the tiles are randomly generated how ever I ran into an error:
Array index is out of range

This is my code:
using UnityEngine;
using System.Collections;

public class TileManager : MonoBehaviour
{
    public GameObject currentTile;
    public GameObject[] tilePrefabs;

    private static TileManager _instance;

    public static TileManager Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = FindObjectOfType<TileManager>();
            }
            return _instance;
        }
        
    }


    void Start()
    {
        for (int i = 0; i < 10; i++)
        {
            SpawnTile();
        }
    }

    void Update()
    {

    }

    public void SpawnTile()
    {
        //random number between 0 and 1
        int randomIndex = Random.Range(0, 2);
        currentTile = (GameObject)Instantiate(tilePrefabs[randomIndex], currentTile.transform.GetChild(0).transform.GetChild(randomIndex).position, Quaternion.identity);
    }
}

Not sure how I would go on and fix it.

Hey! You did not clarify how Long the Array should be.

You should set in

 tilePrefabs = 2;

else the System does not know how Long the array should be.
And make sure that u got 2 elements in :wink: