The code above has an array that is filled with imageobjects
manually filled via the inspector in unity. But when I try to change the sprite of the image in index 0 of the list I get the error message:
NullReferenceException: Object reference not set to an instance of an object at line 13 which indicates that the array is null, which doesn't make sense.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Inventory : MonoBehaviour
{
public Image[] characters;
public Sprite character;
public void createInventory(){
for (int i = 0; i < characters.Length; i++){
characters[i].sprite = character;
Debug.Log(characters); //object reference not set to an instance of an object
}
}
}