M
M
MadDog13372021-08-11 21:14:45
Arrays
MadDog1337, 2021-08-11 21:14:45

Gives an error: index was outside the bounds of the array. Why is it being issued?

public GameObject BuyButton;
    public int BuyCard = 0;
    public GameObject[] VideoCard;
    
 public void Save()
    {
        PlayerPrefs.SetString("VideoCard", JsonUtility.ToJson(VideoCard));
    }

    public void Load()
    {
        VideoCard = JsonUtility.FromJson<GameObject[]>(PlayerPrefs.GetString("VideoCard"));
    }


    private void Start()
    {
        BuyCard = PlayerPrefs.GetInt("BuyCard", BuyCard);
        Load();
    }

    public void BuyCards()
    {
        if (Money1 >= 299)
        {
            BuyCard++;
            Money1 -= 299;
            PlayerPrefs.SetInt("Money1", Money1);
            PlayerPrefs.GetInt("BuyCard", BuyCard);
            VideoCard[0].SetActive(true);
            Save();
        }
    }


Gives an error on the line VideoCard[0].SetActive(true); The array itself consists of 5 elements (in the unit inspector), I don’t understand why it throws an error.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question