darkal
1
this is the code i just want it to show the other buttons when i click click the inventory button.
i am not having any errors so thats good just not showing it when i click it
var inbw = 0;
var inbh = 0;
var weaponhight = 100;
var armorhight = 125;
var clothinghight = 150;
var jewerlyhight = 175;
var bw = 500;
var size = 100;
var size1 = 25;
function OnGUI()
{
if (GUI.Button(Rect(inbw, inbh, size, size1), "Inventory"))
{
if (GUI.Button(Rect(bw, weaponhight, size, size1), "Weapons"))
{
}
if (GUI.Button(Rect(bw, armorhight, size, size1), "Armor"))
{
}
if (GUI.Button(Rect(bw, clothinghight, size, size1), "Clothing"))
{
}
if (GUI.Button(Rect(bw, jewerlyhight, size, size1), "Jewerly"))
{
}
}
}
This is actually quite a common mistake for beginners.
Currently, your inventory (“Weapons, Armour, Clothing …”) is within your:
if (GUI.Button(Rect(inbw, inbh, size, size1), "Inventory")){
Which means that if you are to press it, the Inventory list will show … but only for 1 frame (I believe). You need to create a boolean to trigger your GUI Inventory list:
var inventoryActive : boolean = false;
function OnGUI(){
if (GUI.Button(Rect(inbw, inbh, size, size1), "Inventory")){
//Give the opposite value (true will = false, false will = true)
inventoryActive = !inventoryActive;
}
if(inventoryActive){
//Put your buttons in here
}
}
Try that 
perchik
3
The problem is that the if statement only executes when the button is pressed. I imagine if you click and hold the ‘Inventory’ button, your GUI might show up.
A way around this is to set some kind of flag or marker to tell it that you pressed the inventory button:
var showInv: bool = false;
function OnGUI()
{
if (GUI.Button(Rect(inbw, inbh, size, size1), "Inventory"))
{
showInv=true;
}
if(showInv){
if (GUI.Button(Rect(bw, weaponhight, size, size1), "Weapons"))
{
}
if (GUI.Button(Rect(bw, armorhight, size, size1), "Armor"))
{
}
if (GUI.Button(Rect(bw, clothinghight, size, size1), "Clothing"))
{
}
if (GUI.Button(Rect(bw, jewerlyhight, size, size1), "Jewerly"))
{
}
}
}