hello i am fairly new to this sort of thing but i am trying to make a gui shop open on a button press. the problem im having with this code is that it keeps spamming “hi” and is acting like the button is being constantly pressed. ive been working on this for a while and cant seem to find a fix so any help or tips would be appreciated
#pragma strict
private var ShopOn = false;
var ClosePostition : Vector2 = new Vector2(900,5);
var CloseSize : Vector2 = new Vector2(35,35);
var WindowPostition : Vector2 = new Vector2(0,0);
var WindowSize : Vector2 = new Vector2(900,900);
var ShopWindow : Texture;
var CloseIcon : Texture;
function Start() {
}
function Update () {
if(Input.GetKeyDown("i"))
if(ShopOn == false)
{
ShopOn = true;
}
else if(ShopOn == true)
{
ShopOn = false;
}
}
function OnGUI()
{
if(ShopOn == true)
{
GUI.BeginGroup(new Rect(WindowPostition.x, WindowPostition.y, WindowSize.x, WindowSize.y), ShopWindow);
if (GUI.Button(Rect(ClosePostition.x, ClosePostition.y, CloseSize.x, CloseSize.y), CloseIcon)){
print("Hi");
}
GUI.EndGroup();
}
}