- Home /
Trying to make a button fit exactly with an image
Hi.
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.
Answer by Steffen Franz · Jan 26, 2011 at 12:39 AM
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), ........
Your answer
Follow this Question
Related Questions
Is it possible to detect which GUIStyleState is used? 2 Answers
Problems with GUI relative coordinates once the game is published for web view 1 Answer
Why is my code duplicating the name of a button? styling gui 1 Answer
How can you do a custom GUIStyle image position? 1 Answer
Changing the font size of a GUI.Button in the inspector 1 Answer