script error: index was outside the bounds of the array

repost due to the mess of code uploaded here just now.
I had checked for several time, no any of my index is out of bounds, I really lost here.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{

    public GameObject[] level;   //6 referenced gameobjects
    float[] lvlunlock = new float[6];
 
 

    void Awake()
    {
        lvlunlock[1] = PlayerPrefs.GetFloat("lvl2_unlock", 0);
        lvlunlock[2] = PlayerPrefs.GetFloat("lvl3_unlock", 0);
        lvlunlock[3] = PlayerPrefs.GetFloat("lvl4_unlock", 0);
        lvlunlock[4] = PlayerPrefs.GetFloat("lvl5_unlock", 0);
        lvlunlock[5] = PlayerPrefs.GetFloat("lvl6_unlock", 0);



        for (int i = 1; i < level.Length; i++)
        {
            Debug.Log(lvlunlock.Length);
        
            if (lvlunlock[i] == 0)
            {
                level[i].GetComponent<Button>().interactable = false;
            }
            else if (lvlunlock[i] == 1)
            {
                level[i].GetComponent<Button>().interactable = true;
            }
        }

    }


    public void StartLvl()

    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }

  public void quit()
    {
        Application.Quit();
    }

    #region levelunlock
    public void enterlvl_2()
    {
        level[1].GetComponent<Button>().interactable = true;
        PlayerPrefs.SetFloat("lvl2_unlock", 1);
    }
    public void enterlvl_3()
    {

        level[2].GetComponent<Button>().interactable = true;
        PlayerPrefs.SetFloat("lvl3_unlock", 1);
    }
    public void enterlvl_4()
    {

        level[3].GetComponent<Button>().interactable = true;
        PlayerPrefs.SetFloat("lvl4_unlock", 1);
    }
    public void enterlvl_5()
    {

        level[4].GetComponent<Button>().interactable = true;
        PlayerPrefs.SetFloat("lvl5_unlock", 1);
    }
    public void enterlvl_6()
    {

        level[5].GetComponent<Button>().interactable = true;
        PlayerPrefs.SetFloat("lvl6_unlock", 1);
    }
    #endregion levelunlock


}

error at line 56,74 and 80 . I can call the function of enterlvl 3 and 4 without problem, only those, thats really weird. Help me out,Thanks in advanced!

I see that you might be loading new scenes. Check that the references you set in the inspector are still there. If they are in bold for example, it means that those references are hard scene references, and you should avoid this kind of references. Make prefabs with references only contained inside that prefab.
Don’t know if this is the issue but could be.

I notice you never initialize the “level” variable. Does that mean you have set its values in the inspector?

Before each of those lines, add Debug.Log("$level.Length is {level.Length}", this);. This will help narrow down the issue.

Your $ is in the wrong location.

Debug.Log($"level.Length is {level.Length}", this);

Er, yes, that one.

That level is reference to gameobject in inspector window, and yes I had put 6 there. I had put debug log too, the value is correct. But the problem never solve, I dont know why…