GUI Button with both texture and text?

I’m currently working for inventory system for my game and to show items I have made icons and would want to put both item name and icon on inventory screen as button.

I’m looking for something like this:

1

Sorry for bad paint mockup, but I’m on my gf laptop and it lacks civilized graphical programs.

Here’s a C# example on how to use GUIContent, and how to set the content in GUI.skin for your button.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour
{
	GUIContent content = new GUIContent();
	public Texture2D image;
	string text = "ButtonText";
	
	void Awake()
	{
		content.image = (Texture2D)image;
		content.text = text;
	}
	
	void OnGUI()
	{
		GUI.skin.button.normal.background = (Texture2D)content.image;
		GUI.skin.button.hover.background = (Texture2D)content.image;
		GUI.skin.button.active.background = (Texture2D)content.image;
		
		if(GUI.Button(new Rect(0, 0, 128, 128), content))
		{
			//Do Something.	
		}
	}
}

GUI.Button(new GUIContent(“text”, icon));

Sry I am late, but the solution is so obvious! Since it’s impossible!

If I get you right you want to create the standard unity-gui button-layout!
A clickable Button with an image, and a text above it?

Well take a closer look at Unity’s buttons, their text elemts are all childed gui text.
So what you need to do is to create your button and than create a gui-text which you than child to the button to make it inherit the button-behaviour.
Else if you’d just overlay it the space where the text is displayed wouldn’t be clickable.
and I simply don’t recommend creating two overlaying buttons, one with an image and the next one with your text.
Always remember that order and childing matters in GUI!

hope this may help,

best wishes,
kayb14

ps: just stumbled across this problem on my own, so I’ll put up the code if I am done figuring it out…

is it possible to change an image to the GUIButton by a code?,
is it possible to assign an image to the texture2D by a code?