- Home /
GUISkin & Scripting
Thus far, I've created a new GUISkin and under the GUIStyle Button, I've imported and placed 3 png files under Normal bg, Hover bg and Active bg.
I created a new Javascript with this codes:
var toolSkin: GUISkin; var Button = true;
function OnGUI () {
GUI.skin = toolSkin;
GUI.Button (Rect (0,500,230,200), "");
}
This allows the button to appear and gives 3 different forms when it is untouched, when I get near to the button and when I click on it.
However, how do I reduce the space around the button so that it only changes when I hover over it and not when I'm hovering around the space of the button? Also, how do I allow the active bg to stay active once I clicked on it, and revert back to hovering state once I unclicked it?
Any help would be glady appreciated, thank you!
Answer by jahroy · Jun 14, 2011 at 07:29 AM
You can also draw a toggle button and use the button style that you already altered like this:
GUI.Toggle(Rect(0, 0, 100, 100), isToggleOn, "button");
You can apply any style you want to a gui control.
You can also make a small image stretch to fit the rectangle by using the GUIStyle.border property.
By setting the border to (1, 1, 1, 1) you tell the GUI to stretch everything but the outermost pixel of your texture to fit the rectangle.
Thanks for your help!
What I've accomplished thus far is setting up 7 buttons which can go into their normal state, hover state and active state. Also, I've re-edit the canvas size for my pentagon buttons so that the rectangular background around it originally is smaller in size now.
However, the problem now is that when I click on one button, all 7 light up. If you don't $$anonymous$$d, could you look through this question as well? "http://answers.unity3d.com/questions/129813/using-guitoggle-to-onoff-buttons.html" It's alright though if you're busy!
I just posted an answer to your other question. Good luck!
Answer by Bunny83 · Jun 14, 2011 at 04:36 AM
What do you mean by "unclicked"? a Button is not a Toggle.
And to your hover problem you don't get "near" the button, you're ON the button. You've made the button 230x200 ... I guess the background texture is smaller than your actual button...
GUI elements are always rectangular so there's no easy way around that fact (if your image is circle-shaped with alpha or something like that)
So assu$$anonymous$$g under GUIStyle Toggle, I switch over the PNG images to their respective places, how would I get the button to react respectively?
Thanks for that answer for the size of the button! I'd just have to adjust my PSD file to enlarge it.
Edit: OH, I've finally got it! Thanks Bunny for your help! :D
Your answer
Follow this Question
Related Questions
Using GUIToggle to on/off buttons! 5 Answers
Whats wrong with my GUI.Toggle? 2 Answers
GUI Button which looks like a Toggle 0 Answers
How to reset the state of other buttons when clicking on one of them 0 Answers