system
1
Hi,
I would like to make a texture act as a button but can't seem to remove the dark, semi-transparent rectangle underneath it? I get the feeling this is really simple that I'm overlooking?
Here's my script;
(GUI.Button(Rect((Screen.width/2)-25,Screen.height-30,50,25), back_button)
Thanks.
qJake
2
You need to create a custom GUIskin in order to remove the default one that Unity uses for buttons. Once you apply your custom skin, Unity's default button appearance should go away. If it doesn't, just go into your custom GUIskin and change the "Button" style's background texture to be transparent.
http://unity3d.com/support/documentation/Components/gui-Customization.html
If you don't want the default Unity style, you should really look into creating your own GUIskin, however. It's a lot easier and more flexible than simply using textures for everything.
Bampf
3
As the final argument to the GUI.Button call, you can specify a GUIStyle.
Declare a public GUIStyle in your script, and add it as the third argument to your call:
GUI.Button(Rect((Screen.width/2)-25,Screen.height-30,50,25), back_button, myGuiStyle)
By default the GUIStyle will have no background textures defined for the control, so you should only see your own texture.
(Note about previous answer: a GUISkin consists of many GUIStyles, so it's a great way to create your own "look" for different types of controls. If you are only dealing with a couple control types you can get by with just GUIStyles.)
The above answers are not complete and simple for a novice, and combined with my attention span of a fly, convolute answers is potenchil inefficient… you have to use GUIstyle.none
this one:
if (GUI.Button(Rect(320,10,240,60),myTexture2D,GUIStyle.none)){ etc }
so here is an example of a custom grid using a texture, clic wherever on texture grid it will print the button ofthe grid pressed:
function OnGUI(){
var gridpixels = 20;//pixels per grid square
var gidxsquares = 12;//num squares in x direction
if (GUI.Button(Rect(320,10,240,60),grid of buttons texture,GUIStyle.none))
{
var xpos = Input.mousePosition.x - 320 ;
var ypos = Screen.height - Input.mousePosition.y -10;
var result = Mathf.Floor(xpos / gridpixels) + Mathf.Floor(ypos / gridpixels)*gidxsquares + 1;//plus 1 at end for not zero first square
}
}