How to create GUI BUTTON from this

I have that code:


  1. if (GUI.Button(Rect(0,75,200,25), "Grass = "+grassAmount))
  2. {
  3. selectedBlock = grassBlock;
  4. }

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?

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.