1 Replies - 1353 Views - Last Post: 08 March 2013 - 06:52 AM Rate Topic: -----

#1 TrewSx  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 50
  • Joined: 07-June 12

Hide/Show inventory - JS

Posted 08 March 2013 - 06:49 AM

Hello,
i am trying to do an inventory system in Unity for RPG game. In the code below is an inventory but when i press 'i' it does not appear on the screen, although in the Inspector it seems to be turning on and off.
Could anyone please help me with that ?

//Inventory script


//Inspector variables
var quitInv 					: boolean = false;
var Inventory					: Array;								//Our inventory 		
var iconWidthHeight 		= 20; 										//The pixel size (height and width) of an inventory slot
var spacing 				= 4;										//Space between slots (in x and y)



public var emptyText			: Texture;								//This will be drawn when a slot is empty
public var inventorySizeX 	= 5;										//The size of the inventory in x and y dimension		
public var inventorySizeY 	= 10;									
public var offSet 			= Vector2( 100, 100 );						//set the position of the inventory
   
       
function Start () {
 
}
 
function Update () {
 
	if(Input.GetKeyDown(KeyCode.Escape)) {
 
		quitInv = !quitInv;
 
	}
 
}
 
function OnGUI () {
 
	if(quitInv == true) {
 
		inventory = new Array(inventorySizeX); 
 		for( var i = 0; i < inventory.length; i ++ ) { 
        	inventory[i] = new Array(inventorySizeY);
    	} 
					
 
	}

}


Here is one of my earliest attempts by using Grid which i do not like, because one line of grid seemed to be always on.
//Inventory Script

//Private variables
private var inventoryOpen : boolean;
private var gridValue1 : float = 0;
private var gridValue2 : float = 0;
private var gridValue3 : float = 0;
private var gridValue4 : float = 0;
private var gridValue5 : float = 0;

//Inspector variables
var inventoryTex : Texture;
var Grids : Texture[];


function Update () {
    if(Input.GetKeyUp("i")){
       if(inventoryOpen == false){
       inventoryOpen = true;
       }
       else if(inventoryOpen == true){
       inventoryOpen = false;
       }
    }
}
 
function OnGUI(){

if(inventoryOpen == true){
     GUI.BeginGroup (new Rect (0,0,1024,768),inventoryTex);
     
     //grid
     gridValue1 = GUI.SelectionGrid(Rect(Screen.width / 2 - 50,Screen.height / 2 - 50, 450, 25), gridValue1,Grids, 15);
     gridValue2 = GUI.SelectionGrid(Rect(Screen.width / 2 - 50,Screen.height / 2 - 20, 450, 25), gridValue2,Grids, 15);
     gridValue3 = GUI.SelectionGrid(Rect(Screen.width / 2 - 50,Screen.height / 2 + 10, 450, 25), gridValue3,Grids, 15);
     gridValue4 = GUI.SelectionGrid(Rect(Screen.width / 2 - 50,Screen.height / 2 + 40, 450, 25), gridValue4,Grids, 15);
     gridValue5 = GUI.SelectionGrid(Rect(Screen.width / 2 - 50,Screen.height / 2 + 70, 450, 25), gridValue5,Grids, 15);
 
  	 GUI.EndGroup();
     }
}




Is This A Good Question/Topic? 0
  • +

Replies To: Hide/Show inventory - JS

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8909
  • View blog
  • Posts: 33,396
  • Joined: 12-June 08

Re: Hide/Show inventory - JS

Posted 08 March 2013 - 06:52 AM

Quote

In the code below is an inventory but when i press 'i' it does not appear on the screen,

It may have been ages since I've been in Unity, but just off code comparison alone you would think that the whole "GUI." lines in 'OnGUI' might point to you not drawing a single thing on the screen. Everything in there should be geared to making it happen on the screen.

Perhaps investigating that line of namespaces in the unity help docs would be worth the time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1