I am making a basic inventory with stacking and for some reason whenever i click on the item it subtracts 2 instead of just 1. Can anyone help me? Thank you
void OnGUI ()
{
GUI.DrawTexture(windowRect, inventoryBackgroundTexture);
for (int x=0; x<across; x++)
{
for (int y=0; y<down; y++)
{
Rect buttonRect = new Rect(_offset*2+buttonSize*x, _offset*2.5f+buttonSize*y, buttonSize, buttonSize);
if (inventory[x, y] != null)
{
if (inventory[x, y].itemCount > 0)
{
GUI.DrawTexture(buttonRect, inventory[x, y].texture);
Vector2 mousePos = Input.mousePosition;
mousePos.y = Screen.height-Input.mousePosition.y;
if (buttonRect.Contains(mousePos))
{
if (Input.GetButtonDown("Fire1"))
{
SubtractItem(x, y); *** This part runs 2 times ***
}
GUI.DrawTexture(buttonRect, hoverTexture);
}
if (inventory[x, y] != null)
{
GUI.Label(buttonRect, inventory[x, y].itemCount.ToString(), itemCountStyle);
}
}
}else{
GUI.DrawTexture(buttonRect, blankTexture);
}
}
}
}