New to Unity and need a bit of help (yes I have read all the documentation on UnityGUI).
Not sure of best ways to do:
-
Have an inventory screen show/hide (toggle) when pressing the “I” key.
-
Have the inventory screen appear on the screen? I added it as a GUITexture and could see it fine, but is the best way to do this, or is it better to add the texture to a GUI control like a window?
Any help would be appreciated.
Ok so I think I have solved the “press i to see inv screen” issue. Can someone look at this and tell me if its the best way (C#).
Rect windowRect = new Rect (20, 20, 400, 600);
bool showInventory = false;
float timeSinceLastKeyPress = 0.0f;
//Called every tick
void OnGUI()
{
if (showInventory)
{
windowRect = GUI.Window(0, windowRect, WindowFunction, "Inventory");
}
}
void WindowFunction(int id)
{
GUI.DragWindow(new Rect(0, 0, 10000, 10000));
}
//Called every tick
void Update()
{
timeSinceLastKeyPress += Time.deltaTime;
if (timeSinceLastKeyPress > 0.1f)
{
if (Input.GetKey("i"))
showInventory = !showInventory;
timeSinceLastKeyPress = 0.0f;
}
}
Still not sure if this is best way. For now I am using a GUI Window instead of an inventory texture I created.
If it works then yes.
Can you explain better how to work with GUI and inventory?