I’m trying to make a Inventory system on my game but when i looked at some basic codes from here all i can see are made in JS or they don’t work. Here’s my code so far:
using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour {
void OnGUI () {
if (GUILayout.Button(Rect(10, 70, 100, 40), "Inventory") {
GUILayout.Box(Rect(10, 10, 100, 60), "Inventory");
}
}
}
(GUI.Button(new Rect(10, 70, 100, 40)
will return true only for one frame if the button get clicked. You need to keep that the button was clicked in a permanent variable like this:
using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour {
bool isButtonClicked = false;
void OnGUI () {
if (GUI.Button(new Rect(10, 70, 100, 40), "Inventory")) {
isButtonClicked = !isButtonClicked;
}
if(isButtonClicked){
GUI.Box(new Rect(10, 10, 100, 60), "Inventory");
}
}
}