- Home /
Creating a visual toolbar using an array of GUI Textures
I want to make a toolbar at the bottom of the screen, like in old school FPS games. My idea was to have an array of GUI Textures, however I'm having some trouble implementing it.
1) How would I go about drawing it in the first place? right now, I have it declared as
public Transform[] menuBar;
and then draw it with
GUI.DrawTexture(new Rect(0, 0, 100, 100), menuBar[0]);
but it tells me "cannot convert 'UnityEngine.Transform' expression to type 'UnityEngine.Texture'". I've tried menuBar[0].Texture
and (Texture)menuBar[0]
but those both give me errors as well. How should I go about getting it to match?
2) Once I have it drawn, I'd like to be able to change the object's color depending on whether or not it's selected. How would I go about accessing that?
Thanks so much!
Answer by m0nkeybl1tz · Mar 21, 2014 at 06:02 PM
Ah, I solved it. The solution to both problems was to instantiate it inside of another variable, like so:
heliButton = (GUITexture)Instantiate(menuBar[0].guiTexture);
Definitely a little convoluted, but it looks like it's working.
No, that is correct. Instantiate just creates an object. It does not know what it is. So when you want to assign that object to a variable (heliButton) you must cast is as the appropriate type (GUITexture). You do this no matter what the object is gameObject, Transform, etc.
Well, that is the correct way to Instantiate...
Ins$$anonymous$$d of public Transform menuBar[]; You would write; public guiTexture menuBar[];
Answer by abi-kr01 · Mar 21, 2014 at 04:44 AM
i think you should use plugin for that like ngui or 2dtool kit if u use gui u have to manage the position of ur buttons/menu but these two plugins will allow you to do that without any thing(by anything i mean u wont have to hard code any thing)
$$anonymous$$an, those look cool, but I think they're a little much for what I'm looking to do right now. I did find a cool one called the Buttonator, so if I can't figure it out myself I might just use that...