Inventory Screen

Hey all thanks in advance for the help. I’m following a tutorial and have run into a problem, The “i” will not display the inventory menu on my screen. I have it set to my player with the textures applied. The code is not returning errors. Have I missed something on the Unity side that would not allow this to be displayed? Thanks again! :smile:

//Private Variables

private var InventoryOn = false;

private var scrollBarChopGrid : Vector2 = Vector2.zero;

private var GridValue : float = -1;

//GUI Pos/Size

var ClosePosition : Vector2 = new Vector2(312,5);

var CloseSize : Vector2 = new Vector2(35,35);

var GridPosition : Vector2 = new Vector2(10,2);

var GridSize : Vector2 = new Vector2(323,410);

var ScrollPosition : Vector2 = new Vector2(0,95);

var ScrollSize : Vector2 = new Vector2(353,257);

var WindowPosition : Vector2 = new Vector2(0,0);

var WindowSize : Vector2 = new Vector2(360,360);

//Textures

var InventoryWindow : Texture;

var CloseIcon : Texture;

var Grids : Texture[];

    //On or Off

    if (Input.GetKeyUp("i"))

    {

        if (InventoryOn == false)

        {

            InventoryOn = true;

        }

        else if (InventoryOn == true)

        {

            InventoryOn = false;

        }

    }

function OnGUI()

{

    if (InventoryOn == true)

    {

        GUI.BeginGroup(new Rect(WindowPosition.x, WindowPosition.y, WindowSize.x, WindowSize.y), InventoryWindow);

        //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();

        GUI.EndGroup();

    }

}

Because your Input check isn’t encapsulated in a function. I’m amazed that code doesn’t throw any errors actually. You should place that bit in Update and also improve it as such:

void Update()
{
    if (Input.GetKeyUp(KeyCode.I))
        InventoryOn = !InventoryOn;
}

if (Input.GetKeyUp(“i”)) Needs to be inside a function Update

Yes thank you. I noticed that fiction update was missing as well. Also thanks for the upgraded code!

Also how do I close this thread to answered?