Adding a GUI texture to a GUI.Box script

Hi everyone okay so im going to cut to the chase here and admit im not much of a programmer and more of a designer.
So im having a little trouble with the following issue. I currently have a script that show the ammount of coins i pick up but the GUI box it draws is just the default grey boring box and i want to know what i should add to be able to add a texture to the box.

Here is the script im using:

using UnityEngine;
using System.Collections;

public class CoinCounter : MonoBehaviour 
{

	public static int coinCount = 0;
	
	
	void OnGUI()
	{
		string coinText = "Total Coins: " + coinCount;
		
		GUI.Box (new Rect(Screen.width - 150, 20, 130, 20), coinText);
		
		
	}
	
}

Any help would be appreciated thanks.

You can use GUI Styles or GUI Skins to add your own custom boxes,buttons,labels,windows etc.

GUI Skin :

var newSkin : GUISkin;

function OnGUI(){
GUI.skin = newSkin;

GUI.Box (new Rect(Screen.width - 150, 20, 130, 20), coinText);
}

GUI Style :

var newStyle : GUIStyle;

function OnGUI(){
GUI.Box (new Rect(Screen.width - 150, 20, 130, 20), coinText,newStyle);
}

You can read more about them here :
GUI Skin → Unity - Manual: GUI Skin (IMGUI System)
GUI Style → Unity - Manual: GUI Style (IMGUI System)

 using UnityEngine;
    using System.Collections;
     
    public class CoinCounter : MonoBehaviour
    public GUISkin 
    {
     
        public static int coinCount = 0;
       
       
        void OnGUI()
        {
            string coinText = "Total Coins: " + coinCount;
           
            GUI.Box (new Rect(Screen.width - 150, 20, 130, 20), coinText);
           
           
        }
       
    }

okay so I added public GUISkin
to the script and it seems to ask me to give it a GUISkin and only picks up GUI’s when i search for a skin but what i was wondering is might it be possible to add just a texture? maybe with something like public Texture2D
Or is that for something completely different?

Yeah, you could simply draw a texture to represent the box using “GUI.DrawTexture” or use a GUIStyle. It depends on what you prefer.
Something like this should work. I’ll try and use C# :

private GUIStyle mystyle; 
public Texture myTexture;

void Start(){
//Assign the "myTexture" texture to the box.
myStyle.normal.background = myTexture;
}
void OnGUI(){
GUI.Box (new Rect(Screen.width - 150, 20, 130, 20), coinText,mystyle);
}

Good luck.

Awesome thank you after some tweaking it works like a bomb… without the exploding and so on but you get my point.

THANK YOU!!!:smile: