How can i create an image itself as button in Unity Editor Extension?
I used GUI.Button and assigned texture image to it. The problem here is the size of button is bigger than image. Even if i make the size of Button same as Image it doesn’t work. Here is the code I have written…
if(GUI.Button(new Rect(Screen.width-160,0,40,40), Resources.Load(“home”) as Texture)){
Application.OpenURL(“www.google.com”);
}
So i need home image as button without any extra boundary.
Please let me know what modification I need to do.
You need to change the style of the buttons you’re using. You can grab the default style with ‘GUI.skin.box’, and then modify it’s properties:
//Get a copy of the default style for boxes:
GUIStyle style = new GUIStyle(GUI.skin.box);
//Remove button margins, allowing the texture to fill the entire button
style.margin = new RectOffset(0, 0, 0, 0);
//If you want buttons to have no space between them, set the padding too:
style.padding = new RectOffset(0, 0, 0, 0);
//Do your button with the given style:
if(GUI.Button(new Rect(Screen.width-160,0,40,40),
Resources.Load("home") as Texture, style)
{
Application.OpenURL("www.google.com");
}