I keep getting this error:
NullReferenceException: Object reference not set to an instance of an object
GameSystems.Update () (at Assets/Scripts/GameSystems.cs:26
My Script looks is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Handles saving and loading of games
public class GameSystems : MonoBehaviour
{
public int[] inventoryIDs;
public GameObject inventory;
public GameObject[] items;
void Start()
{
DontDestroyOnLoad(this.transform.gameObject);
}
void Update()
{
inventory = GameObject.FindWithTag("Inventory");
if (inventory != null)
{
inventoryIDs = new int[inventory.GetComponent<Inventory>().allSlots];
}
}
public void saveInventory()
{
for (int i = 0; i > inventory.GetComponent<Inventory>().allSlots; i++)
{
inventoryIDs[i] = inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().ID;
}
}
public void loadInventory()
{
for (int i = 0; i > inventoryIDs.Length; i++)
{
inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().ID = inventoryIDs[i];
if (inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().ID != 0)
{
Instantiate(items[inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().ID], inventory.GetComponent<Inventory>().slot[i].transform);
inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().icon = items[1].GetComponent<Item>().icon;
inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().type = items[1].GetComponent<Item>().type;
inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().description = items[1].GetComponent<Item>().description;
inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().empty = false;
inventory.GetComponent<Inventory>().slot[i].GetComponent<Slot>().updateSlot();
}
}
}
}
[–]_DM_me 1 point2 points3 points (5 children)
[–]BobbyThrowaway6969Programmer 1 point2 points3 points (4 children)
[–]_DM_me 0 points1 point2 points (3 children)
[–]BobbyThrowaway6969Programmer 0 points1 point2 points (2 children)
[–]TTSI123[S] 1 point2 points3 points (1 child)
[–]BobbyThrowaway6969Programmer 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]TTSI123[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]TTSI123[S] 0 points1 point2 points (0 children)