- Home /
Creating a GUI.Toolbar with Custom GUIStyle
Hello, I was wondering if it was possible to create a toolbar with 5 buttons each button having a unique mouse over, pressed and not pressed texture. I tried to do this with the following code but after much tinkering it still is not working.
category = GUI.Toolbar(new Rect(5, 5, SHOP_WIDTH - 10, 85), category, categoryName, categoryButtons);
Where category is an int. categoryName is a list of strings. categoryButtons is a list of GUIStyles.
categoryButtons = new GUIStyle[] { mySkin.FindStyle("TB1Button"), mySkin.FindStyle("TB2Button"), mySkin.FindStyle("TB3Button"), mySkin.FindStyle("TB4Button") };
Any ideas?
Thanks Hans
Answer by Jake-L · May 09, 2011 at 07:36 PM
According to the docs GUI.Toolbar doesn't take an array of GUIStyles, so you only can provide one. I think you have two options:
- Try how it looks when you feed GUI.Toolbar with an array of GUIContent that hold your images
- Create your own toolbar: Draw each button on it's own, so you have full control over it's appearance
Jake
Thanks Jake, greatly appreciated. I fooled around with the unity GUI.Toolbar enough now where I think its time to go with your second suggestion and cut my losses and make my own toolbar. Thanks again.
Answer by beco13 · Jun 28, 2011 at 03:49 AM
@HHameline : sorry to interrupt, does your problem solved? I also have the same problem...But I've already got each button unique style, how do I implement it into the toolbar scripts? Thx
Hello, beco13 :D Unfortunately there is no built in way to handle the unique images with the GUI.Toolbar function what you can do is create a group of GUI.Toggles, and using boolean values disable the ones that are not pressed, give the same functionality of a toolbar even if it is longer. How ever it's stable and worked great for me.
I see so the unity doesn't provide the way :)
and how do I do that? I mean setting up the boolean and disabling the others.
You would want to do something along these lines
bool boolA; bool boolB;
if (GUI.Toggle(new Rect(70, 165, 217, 133), boolA, "")) { boolA = true; boolB = false; }
if (GUI.Toggle(new Rect(70, 305, 217, 133), boolB, "")) { boolA = false; boolB = false; }
this is a very simple way of doing it, for instance the one I mad I used custom gui styles with the toggles and a switch statement to control my menu page options but it the the foundation for what you are trying to do. Hope that helps :d
@HHameline : That really2 does help :) thx for your advice I tried the switch statements, but can't figure it out.. LoL
Once again thank you very much
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Custom score texture 2 Answers
How to texture custom terrain pieces? 1 Answer
Cannot paint Texture onto Terrain using Custom Material 2018.4 1 Answer
Create a custom texture from code? 1 Answer