- Home /
Question by
Streamline Games · Oct 31, 2012 at 09:35 PM ·
inventorykeydown
GUI Box Doesn't stay open
Hi guys, i'm creating an inventory, and i'm having a problem, my inventory won't stay open, if i let go of the key "c" Then it'll disappear, it's anoiying, because too use the inv you have to hold the "c" key, i wan't it to toggle, so if the key has been pushed it stays open until its pushed again. Also how would i get it to go into the exact centre, for all resolutions, because on my 1360 x 768 Monitor if i have screen width / 2 it goes to the right.
#pragma strict
var InventoryEnabled = false;
var InvWindow : Texture;
var InvClose : Texture;
function Update () {
if (Input.GetKey("c"))
{
InventoryEnabled = true;
}else
{
InventoryEnabled = false;
}
}
function OnGUI ()
{
if(InventoryEnabled == true)
{
GUI.Box(Rect(Screen.width /2 - 280,Screen.height /2 - 200 ,500,350), "Inventory");
}
}
Comment
Answer by Eric5h5 · Oct 31, 2012 at 09:55 PM
You should use GetKeyDown; GetKey fires every frame the key is down.
Your answer
Follow this Question
Related Questions
c# play animation on key down 1 Answer
show texture on key down 0 Answers
Public inventory system 1 Answer
Locked door and key to open it script 1 Answer
Key Item in C# 1 Answer