Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

My inventory system does not want to store sprites.

Discussion in 'UGUI & TextMesh Pro' started by BrewNCode, Apr 20, 2018.

  1. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    I was doing a tutorial for a Minecraft inventory on Youtube. Everything went well, but at the moment of putting some sprites in my hotbar, the sprite does not show in it. What am I doing wrong?

    https://www.dropbox.com/s/7p42vhyi2u18v2v/Minecraft_Inventory.zip?dl=0

    ^ here you will find the project.

    ^ that is the tutorial that I'm watching.

    I can't make head or tail about my situation. I have rewatched the video so many times.

    PLEASE, help me.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Hard to say without seeing what you've done, but did you add the sprite to the GetComponent<Image>().sprite = YourSpriteHere;
    Something like that? :)
     
  3. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    Oh
    Oh yes, I did. In the dropbox link is my project. You can check it out.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Okay, sure I could probably check it out. No promises :)
     
  5. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    372
    Any help is appreciated :D
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    A tiny part of your code was different from the video I tried to skim through.
    Posting the relevant portion (but keep reading, there was a stopping 'bug').

    Code (csharp):
    1. string c = sr.ReadLine();
    2.        if(c == ","){
    3.            goto AddItem;
    4.        }else if(c == ";"){
    5.             sr.Close();
    6.  
    7.        }else{
    8.  
    9.            Debug.LogError("ItemData does not have correct line ending");
    10.        }
    11.    }
    Stopping bug:
    Move the 'Sprites' folder into the Resources folder. :)
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Okay after a few more moments, I found an obvious issue that I missed. You were starting with 1 item in the database (empty one).
    Now I get more than 1 item showing up.. however, they now appear on top of each other.

    I'll leave it to you from here to work on. :) If you get stuck more later, let me know.