- Home /
How do I make and use a GUI Toolbar in C sharp?
I want to make a gui toolbar so i can go between 3 different menus using tabs. How can I do this. How do I even make a toolbar? Do I have to make it so that my variables that control the inventory on and off go on when you click one of the bars? Can someone please help!
"How I make GUI?" comes off as a little lazy. What's a toolbar to you - a GUI.BOX? You can do that. What are menus, things that appear when if(GUI.BUTTON) is pressed? You can do that. How do I write something that is on/off on click - thats if(true) showStuff - you can do that.
Please revise if you have a specific technical question.
No there is a GUI thing...I don't know what to call it that is actually a GUI.Toolbar and I don't know how to use it.
It doesn't really explain how to do anything with the toolbar other than create it. I looked there first.
Answer by Sildaekar · Mar 12, 2014 at 03:33 AM
The documents located at http://docs.unity3d.com/Documentation/ScriptReference/GUI.Toolbar.html explain the Toolbar's usage and creation process.
Take a look at the example code:
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
public int toolbarInt = 0;
public string[] toolbarStrings = new string[] {"Toolbar1", "Toolbar2", "Toolbar3"};
void OnGUI() {
toolbarInt = GUI.Toolbar(new Rect(25, 25, 250, 30), toolbarInt, toolbarStrings);
}
}
In this code, when Toolbar 1 is selected toolbarInt is set to 0, when Toolbar2 is selected toolbarInt is set to 1. Etc etc..
Just use the integers to determine what menu you are in.
So you could use it like this:
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
public int toolbarInt = 0;
public string[] toolbarStrings = new string[] {"Main Menu", "Options", "Exit"};
void OnGUI() {
toolbarInt = GUI.Toolbar(new Rect(25, 25, 250, 30), toolbarInt, toolbarStrings);
if(toolbarInt==0){
Debug.Log("This is the main menu!");
}else if(toolbarInt==1){
Debug.Log("This is the options menu!");
}else if(toolbarInt==2){
Application.Quit();
}
}
}
If this answers your questions please don't forget to mark this answer :)