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 CB-TV · Jun 27, 2013 at 04:01 PM · inventory

Inventory Add Item Textures Don't Show?

I have an inventory and my InventoryAddItem script doesn't correctly connect to my InventoryGUI script:

InventoryAddItem:

 #pragma strict
     //Private
     var TheInventory : InventoryGUI;
     var TheTextures : PlayerInventory;
     var ArrayGrid = 0;
     
     static var InventoryNewItemAdded = -1;
     
     //Icons
     var BlankIcon : Texture;
     var TheNewItem : Texture;
     
     function Start () 
     {
        TheInventory = GetComponent(InventoryGUI);
        TheTextures = GetComponent(PlayerInventory);
     }
     
     function newItem () 
     {
        if (InventoryAddItem.InventoryNewItemAdded > -1)
        {
           TheNewItem = TheTextures.itemTexture[InventoryAddItem.InventoryNewItemAdded];
           if (ArrayGrid < TheInventory.Grids.length)
           {
              if (TheInventory.Grids[ArrayGrid].image == BlankIcon)
              {
                 TheInventory.Grids[ArrayGrid].image = TheNewItem;
                 ArrayGrid = 0;
                 InventoryAddItem.InventoryNewItemAdded = -1;
              }
              else if (TheInventory.Grids[ArrayGrid].image != BlankIcon)
              {
                 ArrayGrid += 1;
              }
           }
        }
     }

InventoryGUI:

 #pragma strict
 //Private Variables
 private var InventoryOn = false;
 private var scrollBarChopGrid : Vector2 = Vector2.zero;
 private var GridValue : float = -1;
 var myskin : GUISkin;
 
 //GUI Pos/Size
 var NamePosition : Vector2 = new Vector2(30,30);
 var NameSize : Vector2 = new Vector2(250,250);
 var GridPosition : Vector2 = new Vector2(10,5);
 var GridSize : Vector2 = new Vector2(323,410);
 var ClosePosition : Vector2 = new Vector2(312,5);
 var CloseSize : Vector2 = new Vector2(35,35);
 var ScrollPosition : Vector2 = new Vector2(312,5);
 var ScrollSize : Vector2 = new Vector2(355,500);
 var WindowPosition : Vector2 = new Vector2(0,0);
 var WindowSize : Vector2 = new Vector2(360,360);
 var DragWindowPosition : Rect = Rect(0,0,WindowSize.x,WindowSize.y);
 
 //Textures
 var InventoryWindow : Texture;
 var CloseIcon : Texture;
 var Grids : GUIContent[];
 
 function Update () 
 {
    var AddingNewItem : InventoryAddItem = GetComponent(InventoryAddItem);
    //On or Off
    if (Input.GetKeyUp ("i"))
    {
    
       if (InventoryOn == false)
       {
          InventoryOn = true;
       }
       else if (InventoryOn == true)
       {
          InventoryOn = false;
          scrollBarChopGrid.y = 0;
       }
    }
    //Window Drag Fix
    if (Input.GetKey("left shift"))
    {
       if (Input.GetKeyDown("i"))
       {
          DragWindowPosition.x = 0;
          DragWindowPosition.y = 0;
          
       }
    }
    AddingNewItem.newItem();
 }
 
 function OnGUI()
 {
    GUI.skin = myskin;
    if (InventoryOn == true)
    {
       DragWindowPosition = GUI.Window(0, DragWindowPosition, DoMyWindow, "");
    }
 }
 
 function DoMyWindow(windowID : int)
 {
    if (InventoryOn == true)
    {
       GUI.BeginGroup(new Rect(WindowPosition.x, WindowPosition.y, WindowSize.x, WindowSize.y), InventoryWindow);
          //Name
          GUI.Label(Rect(NamePosition.x, NamePosition.y, NameSize.x, NameSize.y), "Your Inventory");
       
          //Close Button
          if (GUI.Button(Rect(ClosePosition.x, ClosePosition.y, CloseSize.x, CloseSize.y), CloseIcon))
          {
             InventoryOn = false;
          }
          //Scroll Bar
         scrollBarChopGrid = GUI.BeginScrollView(Rect (ScrollPosition.x, ScrollPosition.y, ScrollSize.x, ScrollSize.y), scrollBarChopGrid, Rect(0,0,0,420));
             // Grid
             GridValue = GUI.SelectionGrid(Rect(GridPosition.x, GridPosition.y, GridSize.x, GridSize.y), GridValue, Grids, 5);
          GUI.EndScrollView();
          
          //Dragable Window
          GUI.DragWindow (Rect (WindowPosition.x, WindowPosition.y, 10000, 40));
       GUI.EndGroup();
          
    }
 }

Does anyone know why I can't see the inventory item texture in my inventory?

Comment
Add comment · Show 19
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 Graham-Dunnett ♦♦ · Jun 27, 2013 at 04:01 PM 2
Share

You might want to format that code. ;-)

avatar image slayer29179 · Jul 05, 2013 at 09:07 PM 0
Share

Play with your scroll-bar size and position to make the grids and scroll-bar visible.

I just assigned all the variables and it all worked fine.

$$anonymous$$ake sure in your Inventory Add Item you have: Your blank icon variable set

In your InventoryGUI you have that same blank icon on all the empty slots. Also change your scroll-bar options.

In your PlayerInventory make sure you have set the item textures correctly for example -

ID 0 - Is the apple, and the 0 value in the array is an apple.

Hope this helps!

avatar image CB-TV · Jul 06, 2013 at 08:01 AM 0
Share

I played with the size and it was all visible. I have the BlankIcon set in my Inventory Add Item. I'm not sure that I have the BlankIcon set in those empty slots-how do I check? All the textures have the correct ID's. Do you know how to see if the BlankIcon is in the empty slots?

avatar image slayer29179 · Jul 06, 2013 at 08:04 AM 0
Share

Go to your InventoryGUI in the inspector and look for the grids variable. $$anonymous$$ake the array equal 1, and put the blank icon in the images. Then make it 40 and they will all have the icon :)

avatar image CB-TV · Jul 06, 2013 at 10:13 AM 1
Share

Ok i will do that

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by slayer29179 · Jul 06, 2013 at 10:09 AM

Play with your scroll-bar size and position to make the grids and scroll-bar visible.

I just assigned all the variables and it all worked fine.

Make sure in your Inventory Add Item you have: Your blank icon variable set

In your InventoryGUI you have that same blank icon on all the empty slots. Also change your scroll-bar options.

In your PlayerInventory make sure you have set the item textures correctly for example -

ID 0 - Is the apple, and the 0 value in the array is an apple.

Hope this helps!

Comment
Add comment · Share
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

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Inventory Script not working 1 Answer

Locked door and key to open it script 1 Answer

Inventory system? 3 Answers

Key and Door Tutorial Help? 2 Answers

Simple Backpack "Pick up and drop" 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