I ran into a problem when I tried to store GUI elements like GUI.Toolbar in a variable.
I need to attach a script to some GUI elements to make them accessible via a multitouch table. Actually, I'd like to store the Toolbar in a variable and add the script as a component to it, but it seems this is not the appropriate solution in Unity. I cannot store the Toolbar in a variable, because the return type is an Integer, representing the selected element in the Toolbar.
Is there any possibility to attach scripts to GUI elements I created this way? If not, does anyone have a good advice to look at this from a different angle?
By the way, I'm using C# scripts.
edit: @Jesse Anders I'm trying to attach a script to that toolbar. I have not written this script by myself since it belongs to a set of scripts called uniTUIO. uniTUIO is used to process input events from the TUIO interface, which can be touches from a multitouch table. The implementation is very basic and I didn't even find a proper documentation for how to use their scripts. And now that I know that I have to add a certain script to the objects I want to become "multitouchable", I need to find out how to do so.
edit2: While trying a bit harder to analyze the actual reason why I would need to add that script to a toolbar, I searched around the uniTUIO forums and found a surprisingly simple answer to my question on how to add the multitouch-functionality uniTUIO provides to GUI created by scripts with onGUI. "Sorry - no chance with the regular onGUI stuff." Sad but true.
I need to reconsider faking the Toolbar then. The current way of dealing with this problem seems to be using a GUITexture as a GameObject and modificate it. I have not fully understood how it works, yet.
As for my initial question "How to attach a script to a toolbar created with GUI.Toolbar", it's simply not possible since objects created that way are no GameObjects. Statement's advice using a delegate will do for most purposes, I guess. Thanks a lot for the answer, nevertheless. I'm sure I'll need that pattern anyway.