You code, “if(Input.GetButtonDown(“Mouse X”))”, has nothing to do with your toolbar; that’s actually asking if the mouse has moved horizontally, which is obviously not what you want. You’re also resetting the list of buttons in the toolbar to just one item, which will make all the other buttons disappear. Probably also not what you want.
Here’s a more typical usage (omitting the code that’s irrelevant to the question):
var toolbarInt = 0;
var toolbarStrings : String[] = ["Lobby", "Play", "Shop", "LeaderBoard", "Chat"];
function OnGUI ()
{
toolbarInt = GUI.Toolbar (Rect (5, 42, 505, 45), toolbarInt, toolbarStrings);
}
function Update ()
{
// If clicked go to lobby
if (toobarInt == 0)
{
Debug.Log("You selected Lobby");
}
else if (toolbarInt == 1)
{
Debug.Log("You selected Play");
}
else if ...
}
It should work (excepting any syntax errors); it just may not do what you want – you haven’t really described what you’re trying to achieve.
You’re still confusing GUI input/interaction with general mouse input. What that code is doing:
Draw a GUI button, but ignore whether it gets clicked or not
See if mouse button one was pressed down this frame, regardless of where the mouse may be
If the mouse was clicked, anywhere, call LoadLevel(“Main Menu”)
You then continue in the same vein – so, what this code will do is: draw 5 buttons but ignore them; check to see if the mouse was clicked and, if so, load all five levels (since if the mouse button is pressed, Input.GetMouseButtonDown(0) will return true every time you call it).
You really need to re-read the GUI Scripting Guide and make sure you’re following the structure of the code in the examples. In this case what you wanted would look more like:
function OnGUI ()
{
if (GUI.Button (Rect (5, 43, 90, 40), "Lobby"))
{
Application.LoadLevel ("Main Menu");
}
...
}
You need to test if the button was clicked, not just if the mouse was clicked.