How to create GUI BUTTON from this
I have that code:
if (GUI.Button(Rect(0,75,200,25), "Grass = "+grassAmount))
{
selectedBlock = grassBlock;
}
and I want my texture in button. Previously I did that:
GUI.BeginGroup(new Rect(200, 50, 25, 25), "");
GUI.EndGroup();
for the boxes, but in buttons it doesnt work:
if(GUI.BeginGroup(new Rect(200, 50, 25, 25), DirtText,""+dirtAmount)) or anything else not working
How to create texture button from first example?
Why don't you use Unity 4.6's UI features? You can still generate it "procedurally" in code. You'd just use prefabs ins$$anonymous$$d.
i dont really know how I can and of course there are a lot of things to move to UI4.6. For some reason i prefer that option (is it possible to make that?)
Answer by ArturoSR · Jul 30, 2016 at 06:39 PM
Hello and good day, of course it is possible, the only thing you have to do is set the GUIContent(string name, Texture2D image), the code will be something like this:
string name;
Texture2D image;
GUIContent content = new GUIContent (name, image);
GUILayout.Button(content);
But if you want to make something more complicated you need to think about the button like a group of layers, something like this:
Background
Text
Sub-Element
This is important, you need to have at least the button element defined, I recomendad to check the documentation, particularly about Editor, there is a lot of basic info that could help you, cheers.
Your answer
Follow this Question
Related Questions
Trouble with GUI Button Level switching. 0 Answers
Animated GUI button 0 Answers
how can I open url link in Unity/Vuforia android app 2 Answers
Object move around side window 0 Answers