Retrieve Values from Toolbar

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. :slight_smile:

Thanks.

I would greatly appreciate any advice. I think my methodology is horribly flawed. I’ve been playing with it for hours now and keep running into roadblocks.

I’m looking to create a selection system. The player will have some objects displayed and select them. These objects will be stored in an array. It seems simple, and I would have less trouble doing it with game objects as buttons than with the GUI. My issues are:

  1. Since the objects vary by scene, I need an initial array to display choices, then the selected objects get stored in a second array where they can be used during the scene.
  2. I’m conflicted with making the menu in the Unity GUI or creating Game Objects and using OnMouseDown functions to accomplish what I want.
  3. I want the menu items or game objects to move smoothly instead of disappearing. I can accomplish this if I use game objects but my attempts to make it work with a GUI seem overly complex. It seems to mainly be due to having to create separate variables for each menu box when you’re not certain how many boxes you will have. I can probably mathematize my way through this issue but I’m hoping that there is a method/tool that I am simply overlooking.

Thanks.