Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheMagzuz · Apr 02, 2015 at 06:11 PM · c#texture2d

Inventory image not showing up

I have made a inventory system but when i open the inventory, i just see the slots, not the items. What do i do? Here are the scripts:

Item:

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class Item {
     public string itemName;
     public int itemID;
     public string itemDesc;
     public Texture2D itemIcon;
     public int attackDMG;
     public int attackSpeed;
     public int def;
     public int manaUse;
     public ItemType itemType;
 
     public enum ItemType {
         MeleeWeapon,
         Consumable,
         Block,
         Crafting,
         Gun,
         Spell,
         Helmet,
         Chestplate,
         Leggins,
         Boots
     } 
 
     public Item(string name, int id, string desc, int DMG, int speed, int manaUseage, ItemType type) {
         itemName = name;
         itemID = id;
         itemDesc = desc;
         itemIcon = Resources.Load<Texture2D>("Item Icons/ " + name);
         attackDMG = DMG;
         attackSpeed = speed;
         manaUse = manaUseage;
     }
     public Item(){
 
     }
 
 }

ItemDatabase:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ItemDatabase : MonoBehaviour {
     public List<Item> items = new List<Item>();
     
 }

And finally, Inventory:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Inventory : MonoBehaviour {
     public int slotsX, slotsY;
     public List<Item> inventory = new List<Item>();
     public List<Item> slots = new List<Item>();
     private ItemDatabase database;
     public bool showInventory = true;
     public GUISkin skin;
 
     // Use this for initialization
     void Start () {
         for (int i = 0; i < (slotsX * slotsY); i++) {
             slots.Add (new Item());
             inventory.Add (new Item());
         }
 
         database = GameObject.FindGameObjectWithTag("Item Database").GetComponent<ItemDatabase>();
         AddItem (0);
         print (InventoryContains(0));
         print (InventoryContains(1));
     }
 
     void Update(){
         if (Input.GetKeyDown(KeyCode.I)){
             showInventory = !showInventory;
         }
 
     }
 
     void OnGUI(){
         for (int i = 0; i < inventory.Count; i++) 
         {
             GUI.skin = skin;
         }
         if(showInventory){
             DrawInventory();    
         
         }
     }
     void DrawInventory() {
         int i = 0;
         for (int x = 0; x < slotsX; x++){
             for (int y = 0; y < slotsY; y++){
                 Rect slotsRect = new Rect(x * 60, y * 60, 50, 50);
                 GUI.Box(slotsRect, "" , skin.GetStyle("slot"));
                 slots[i] = inventory[i];
                 if (slots[i].itemIcon != null) {
                     GUI.DrawTexture (slotsRect, inventory[i].itemIcon);
                 }
                 i++;
             }
         }
     }
     void AddItem(int id) {
         for (int i = 0; i < inventory.Count; i++){
             if (inventory[i].itemName == null){
                 for (int j = 0; j < database.items.Count; j++){
                     if (database.items[j].itemID == id){
                         inventory[i] = database.items[j];
                     }
                 }
 
                 break;
             }
         }
     
     
     }
 
     bool InventoryContains (int id){
         bool result = false;
         for (int i = 0; i < inventory.Count; i++){
             result = inventory[i].itemID == id;
             if (result) {
                 break;
             }
         }
         return result;
     }
 
 }


Images:

The hierarchy: The hierarchy

The item database: Item Database

The inventory object: Inventory

What appears: Popup

What SHOULD appear (I edited the image): What Should Appear

Edit: Now, when i open the inventory i get a single inventory square and get spammed with an error saying something on the lines of "Argument is out of range"

Edit Edit: I don't get the error(s) anymore, now the image just doesn't show up. I've tried adding the item by index creating a test item. So it seems that it's something that's wrong with the DrawInv function.

inventory.jpg (19.4 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eno-Khaon · Apr 02, 2015 at 06:35 PM 0
Share

Are there any error messages stopping the script's execution?

If not, are the textures being loaded properly? (i.e. line 50, is it deter$$anonymous$$ing the texture to be null?)

At any rate, is the first slot, for instance, properly receiving data on the sword in the first place? If not, do any of the slots technically have the data for it?

avatar image TheMagzuz · Apr 02, 2015 at 10:21 PM 0
Share

Do any of the slots technically have the data for it?

Yes, in the inventory script there's a "InventoryContains" function, and that says that i have the sword. The only problem is that there is no texture. I don't get any errors/warnings when i start the game nor when i open the inventory
avatar image saschandroid · Apr 14, 2015 at 11:01 AM 0
Share

Have you solved your problem? Because:

 itemIcon = Resources.Load<Texture2D>("Item Icons/ " + name);

There is a space after the "/". Is this intentionally?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Can not retrive image form device to the plane at runtime. 0 Answers

Texture2D.Resize and Shader 0 Answers

What is an element in CopyTexture ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges