I have Inventory.cs script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Inventory : MonoBehaviour {
public List<Item> inventoryItems;
void Start () {
inventoryItems = new List<Item>();
}
}
public class Item
{
private string name;
private int quantity;
public string Name { get { return name; } set { name = value; } }
public int Quantity { get { return quantity; } set { quantity = value; } }
}
Everything is working. But when i try to get inventoryItems list from other class i get: Object reference not set to an instance of an object.
InventoryGUI.cs script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class InventoryGUI : MonoBehaviour
{
public GameObject player;
public Inventory inventory;
void Start()
{
inventory = player.GetComponent<Inventory>();
Debug.Log(inventory.inventoryItems.Count);
}
}
I can get int or float from Inventory.cs script. But how can i get inventoryItems list?