- Home /
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?
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!
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?
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 :)
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!
Your answer
Follow this Question
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