Question by
CreationAl3xStudio · Aug 21, 2020 at 02:30 PM ·
nullreferenceexceptionnullsingletonnullreferenceexeption
NullReferenceException: Object reference not set to an instance of an object error
This is my script : using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class GameManager : MonoBehaviour {
public bool isPaused;
public List<Item> items = new List<Item>();
public List<int> itemNumbers = new List<int>();
public GameObject[] slots;
public Dictionary<Item, int> itemDict = new Dictionary<Item, int>();
public static GameManager instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
}
else
{
instance = this;
}
DontDestroyOnLoad(gameObject);
}
private void Start() => Displayitems();
private void Displayitems()
{
for (int i = 0; i < items.Count; i++)
{ //UPDATE slots Item Image
slots[i].transform.GetChild(0).GetComponent<Image>().color = new Color(1, 1, 1, 1);
slots[i].transform.GetChild(0).GetComponent<Image>().sprite = items[i].itemSprite;
//UPDATEE slots Count Text
slots[i].transform.GetChild(1).GetComponent<Text>().color = new Color(1, 1, 1, 1);
slots[i].transform.GetChild(1).GetComponent<Text>().text = itemNumbers[i].ToString();
//UPDATE CLOSE/THROW button
slots[i].transform.GetChild(2).gameObject.SetActive(true);
}
}
} All it does is it holds the isPausedvariable that is used by another script, which works , and its doing the display of the items in my inventory, wich it apparantely cant do , and im getting the null error...?
Comment
Your answer
Follow this Question
Related Questions
NullReferenceException Help please :> 1 Answer
How to change value of a null element in an array? 1 Answer
NullRefrenceException: Object refrence not set to an instance of an object. 0 Answers
Null Reference Exeption?? 0 Answers
Singleton ScriptableObject unable to Find itself, returns null 2 Answers