Trying to make a button fit exactly with an image


I'm trying to use some texture as an button. The button works well but I can't get to make the button coincide exactly with the size of the image.

It's something really simple like:

public void OnGUI () {

        if (GUI.Button (myrect, mytexture, myguiSkin.button)) {
            Debug.Log ("You clicked the button!");

How can I make the button fit exactly with the image ?. Thanks.

you can get the width and the height from Texture2D, use those for the width and the height of the rectangle to display your button with.

Texture2D image;

if(GUI.Button(new Rect(left, top, image.width, image.height), ........