I'm losing my mind with scriptableobjects and my inventory system

Hello there, i’m trying to calm myself while writing this. For 8+ hours now im sitting on my inventory system, i am missing the World Cup finale, because i just cannot get my Inventory to work. I don’t know that much about coding so please be kind. So. I made objects using scriptable objects and it kinda worked fine. Now i had an Inventory that i really didnt like, it was limited to 20 slots, but i’d prefer one with scroll feature and slots added for each inventory item. Now im completely freaking out because i cannot add any items to my list and im not even close to adding anything to my inventory.

here si my scriptableobject script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[CreateAssetMenu(fileName = "New Item", menuName = "Item")]
public class ItemData : ScriptableObject {

    public new string name;
    public string kaputt;
    public float healthPoints, thirstPoints, hungerPoints;
    public float rate;
    public float maxStack;
    public float counter;

    public Texture artwork;


}

here is my Inventory script(i deleted it completely like 20 mins ago and this is how far ive gotten it since then)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Inventory : MonoBehaviour {

    public populateGrid grid;
    public ItemData data;

    public GameObject ItemPickedUp;
    private Dictionary<string, populateGrid> m_Inventar = new Dictionary<string, populateGrid>();
    public List<populateGrid> Inventar;

    private int slots;
  
   
    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
        List<string> Inventar = new List<string>();

       
        foreach (string counter in Inventar)
        {
            GetComponent<populateGrid>().numberToCreate += 1;
        }
    }
    private void TriggerEnter(Collider other)
    {
        ItemPickedUp = other.gameObject;
        Inventar.Add(data.name);
    }
}

and the script that adds the slots, the only one that kinda works(made it off youtube tutorial)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class populateGrid : MonoBehaviour
{

    public GameObject prefab;

    public int numberToCreate;

    // Use this for initialization
    void Start()
    {
        Populate();
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    void Populate()
    {
        GameObject newObj;

        for (int i = 0; i < numberToCreate; i++)
        {
            newObj = (GameObject)Instantiate(prefab, transform);
            //newObj.GetComponent<Image>().color = Random.ColorHSV();
        }
    }
}

I just hope anyone cann tell me how to proceed, or maybe someone is better at googling than me who can show me a tutorial on how to do it properly( not this one dude with the heathstone cards i cant see it anymore)

Have you tried this Unity one that seems to cover an inventory system?

Stick with it. You’ll get there. :slight_smile:

1 Like

Oh god you’re right… :o