I think may be this is a very simple question ,but is very hard for me.I have search the fourm,find no useable post.I am not familar with unity,and post will be appreciated.
var newgame : Texture2D; if (GUI.Button (Rect (100,100,237,85),newgame)) { print("game run");}
237,85 is newgame widht and height,but I only could see a button,and the texture is small,not as same size as the button size.so ,how can i make the texture as same size as the button?
Actually pretty surprised no one has answered this yet.
I don’t personally code in Java Script, so I’m gonnna’ give this a shot.
When I’m working in GUI (Which is almost always sadly), I write my GUI functions as such:
GUI.Button(new Rect(100,100,237,85), newgame);
The new tells it that it’s a new instance of rectangles. That might be your problem, I’m not posositve. Because the texture should be replacing the button.
Also I’d make sure that you’re putting this code inside of the OnGUI() Function. And just as a side note, your texture will look a lot cleaner if in the editor you go to the inspector with the texture selected in the library and change the type to a gui instead of a texture. It’ll look a lot cleaner when it does show up. Hope this helps.
I think the code is probably fine since it's JavaScript. What I think what is happening is that the image is getting offset by padding or contentOffset. Try making your own GUIStyle:
var tStyle:GUIStyle = GUIStyle(GUI.skin.button);
tStyle.padding = RectOffset();
tStyle.contentOffset = Vector2();
GUI.Button(Rect(0, 0, MyTexture.width, MyTexture.height), MyTexture, tStyle);