gui button textured how to
Hello!
I have that code:
if (GUI.Button(Rect(0,75,200,25), "Grass = "+grassAmount))
{
selectedBlock = grassBlock;
}
How can I change gui.button to mu own texture button in that code?
There are a lot of lines like this, well I prefer to stay with that code if its possible to make it as a texture. Please help~!
Answer by Ruben_Chris · Jul 30, 2016 at 11:32 AM
You could use GUI Style to achieve this:
Javascript:
var myButtonStyle : GUIStyle;
function OnGUI () {
if (GUI.Button(Rect(0,75,200,25), "Grass = "+grassAmount, myButtonStyle))
{
selectedBlock = grassBlock;
}
}
C#:
public GUIStyle myButtonStyle;
void OnGUI () {
if (GUI.Button(new Rect(0,75,200,25), "Grass = "+grassAmount, myButtonStyle))
{
selectedBlock = grassBlock;
}
}
In the inspector where the script is attached, you can modify the normal, hover and active textures in the myButtonStyle dropdown.
I hope this helped you @Drymarti111.
Wow thanks! But is there a way to just add var texture at the end of line? Because I have in that script more than 40 textures and it isn't working well with that ;/
I have var DirtText : Texture;
But when I want to add that for your: myButtonStyle It giving me error
How can i just add myowntexture(1 file texture) to this line?
I see you have created the variable DirtText as a Texture. Have you tried creating it as a Texture2D?
var DirtText : Texture2D;
If that doesn't work, can you copy and paste your error message? @drymarti111