I’m looking to use a toolbar to allow the player to select objects for recall later in the game. I need to use images on the buttons but was hoping to retrieve a value from a button press. Something like this:
var values : GameObject[];
private var selectedToolbar : int = 0;
var toolbarStrings = ["Rock", "Bird", "Bouncy"];
var toolbarImages = [imgRock, imgBird, imgBouncy];
var pressedItem : string;
var Rock = "values.Push(Add Prefab); toolbarStrings.RemoveAt(Num);toolbarImages.RemoveAt(Num)";
var Bird = "values.Push(Add Prefab); Array.RemoveAt(Num);"; //Maybe these should be functions?
function OnGUI () {
selectedToolbar = GUI.Toolbar (Rect (50, 10, 300, 50), selectedToolbar, GUIContent(toolbarStrings, toolbarImages));
if (GUI.changed)
{
if (selectedToolbar == 0)
{
Num = 0;
pressedItem = selectedToolbar.text.0 //Yeah...this won't work
pressedItem;
}
else if(selectedToolbar == 1)
{
Num = 1;
}
}
}
I don’t know how to reference a Prefab to an array via code and I’m not sure how to retrieve the Toolbar text when clicked. It also seems inefficient to have two arrays, one for the text and one for the images. There’s probably a much better way to do the whole thing (hopefully).
I’ve run through the GUI documentation and don’t see information on how to do this. I’m always happy to be pointed to a tutorial or other resource.
Thanks.