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);
}
}
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);
}