Я новичок в unity. Был бы благодарен если помогли решить проблему

У меня вылезает ошибка: IndexOutOfRangeException: Index was outside the bounds of the array. MapManager.Start () (at Assets/Scripts/MapManager.cs:20)

public static int countUnlockedMap = 1;
public MapButtonManager[] mapButton;

// Start is called before the first frame update
void Start()
{
    for(int i = 0; i < transform.childCount; i++){
        if(i < countUnlockedMap){
            transform.GetChild(i).GetComponent<Image>().sprite = mapButton[i].GetComponent<MapButtonManager>().unlockedIcon;
            transform.GetChild(i).GetComponent<Button>().interactable = true;
        }else
        {
            transform.GetChild(i).GetComponent<Image>().sprite = mapButton[i].GetComponent<MapButtonManager>().lockedIcon;
            transform.GetChild(i).GetComponent<Button>().interactable = false;
        }
    }
}

Ответы (1 шт):

Автор решения: HonoLite

Ваша i в строчке transform.GetChild(i).GetComponent<Image>().sprite = mapButton[i].GetComponent<MapButtonManager>().unlockedIcon; превышает кол-во элементов массива

→ Ссылка