In Game Shop

Hi guys,thanks for looking into this question

I have a problem for an shop i am trying to make for my game.I am using a public List (in editor) to add the cost and stuff.

public class Buyable
	{
		public string name;
		public Texture2D CharTexture;
		public int Cost;
            public bool Unlocked;
	}

My problem now is how do i use this to create this
32237-gsg-iconstringcontent.png

with this script

 if (GUI.Button (new Rect (10,10, 100, 50), icon)) {
            print ("you clicked the icon");
        }
    
        if (GUI.Button (new Rect (10,70, 100, 20), "This is text")) {
            print ("you clicked the text button");
        }

like use the (texture 2d) in list to show the texture on the icon and (Name) in list to show the name.

I need to put up a new icon and name for every new element i put in the editor list.I tried to do this my self but i have no idea how to start this and i googled it but no hope.

I tried to explain as detailed as i can.I hope u guys will understand it.Thanks

It actually becomes really easy to add textures to buttons when you stop using strings and start using GUIContent to label your GUI:

Now, we’re interested in the GUI.Button overload that takes a GUIContent:

For example:

public static void DrawCharGUI(Rect position, Buyable buyable)
{
    GUIContent iconButtonLabel = new GUIContent(buyable.CharTexture, "Some Tooltip");
    GUIContent textButtonLabel = new GUIContent(buyable.name, "Another Tooltip");

    GUILayout.BeginArea(position);
    
    if (GUILayout.Button(iconButtonLabel))
        print ("you clicked the icon");
 
    if (GUILayout.Button(textButtonLabel))
        print ("you clicked the text button");

    GUILayout.EndArea();
}

I think you might want to start with the Unity documentation:

GUI Basics Tutorial

GUI.Button reference

I’m sorry for only providing links, but I think writing code for you or extensively explaining how the GUI system works wouldn’t really help you. (also since there already are good tutorials)