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

New Topic/Question
Reply



MultiQuote






|