Hide / show a bag without disabling the script

i got a bag made (mmo style)
using this script (no real inventory tracking or anything yet)

var Bagtxt: Texture2D;
function OnGUI () {
GUI.Box (Rect (Screen.width - 220, Screen.height - 290,210,300),"");
GUI.Label (Rect (Screen.width - 232, Screen.height - 345,232,345), Bagtxt);	
GUI.Label (Rect (Screen.width - 215, Screen.height - 20,220,345),"Gold: 0");	
}

what i want is if i press “B”
it will hide and if i hit B again it will show again,
but without disabling whatever script i may put in it later

so please modify my script here if you know how to make it hide and show :slight_smile:

thansk alot in advance

you could use B to toggle a boolean var and in the gui script do something like

if(booleanVar)
{
GUI.Box(…);
}

i didnt get any of that :stuck_out_tongue: im a TOTAL noob to this stuff… anyone can make an example?
thansk in advance

Something like this should do the trick:

var b_display_bag : boolean = false; //default value is "false"
var Bagtxt : Texture2D;

function Update () {
    if (Input.GetKeyDown ("B")) {
        b_display_bag = !b_display_bag; //the exclamation point means "not", so this line switches false to true, or true to false
    }
}

function OnGUI () { 
if (b_display_bag) { //if b_display_bag is true, the next 3 lines will run
    GUI.Box (Rect (Screen.width - 220, Screen.height - 290,210,300),"");
    GUI.Label (Rect (Screen.width - 232, Screen.height - 345,232,345), Bagtxt);
    GUI.Label (Rect (Screen.width - 215, Screen.height - 20,220,345),"Gold: 0");
}
}

dude i love you xD Thanks alot! worked perfectly! except for capital b hehe, but after that 100% what i was looking for, thanks alot!