@Daniil2411

Ошибка в юнити: IndexOutOfRangeException: Index was outside the bounds of the array?

Здраствуйте, создавал инвентарь для игры и столкнулся с такой ошибкой : "IndexOutOfRangeException: Index was outside the bounds of the array."

Вот код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class sobiraenpredmetu : inventoryipob
{
    private inventoryipob inventoey;
    public GameObject slotButton;

    private void Start()
    {
        inventoey = GameObject.FindGameObjectWithTag("Player").GetComponent<inventoryipob>();
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            for (int i = 0; i < inventoey.slots.Length; i++)
            {
                if(idfull[i] == false)
                {
                    idfull[i] = true;
                    Instantiate(slotButton, slots[i].transform);
                    Destroy(gameObject);
                    break;
                }
            }
        }
    }
}


Посмотрел несколько сайтов в интернете, но так и не понял.

Ps. Прошу объяснить подробно, так как я новичок в этом деле.
  • Вопрос задан
  • 2092 просмотра
Пригласить эксперта
Ответы на вопрос 1
rundll32
@rundll32
Сама ошибка говорит о том, что вы обращаетесь к индексу, превышающему размер массива. В Вашем коде не понятно, как Вы создаете инвентарь, но ошибка или в slots или idfull (что скорее).
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы