- Home /
Cloning custom skin style
Hi all,
I've spent about a day searching the forums and trying to figure this out but not had any luck :(
Any way I have a custom skin that is called 'myGUISkin', I am trying to clone the toggle style (in the skin) so I can use different textures.
Here's the code:
public GUISkin myGUISkin;
void OnGUI()
{
GUI.skin = myGUISkin;
RenderSettings.fog = GUILayout.Toggle(RenderSettings.fog, "123", myStyleBtnFog);
}
void Start () {
GUIStyle myStyleBtnFog = new GUIStyle(myGUISkin.GetStyle("toggle")); //This line seems to be the problem
myStyleBtnFog.normal.background = (Texture2D)Resources.Load("GUITextures/ButtonLightUp");
myStyleBtnFog.onNormal.background = (Texture2D)Resources.Load("GUITextures/ButtonLightDown");
myStyleBtnFog.hover.background = (Texture2D)Resources.Load("GUITextures/ButtonLightHover");
}
I have tried many alternatives I found on the forums, here is what I have tried:
GUIStyle myStyleBtnFog = new GUIStyle(GUI.myGUISkin.toggle);
GUIStyle myStyleBtnFog = new GUIStyle(myGUISkin.toggle);
(this one doesn't give me any errors but I doesn't seem to adopt the original settings from the toggle style)
Any help would be greatly appreciated.
Thanks in advance
Comment
Answer by veddycent · Aug 21, 2013 at 04:05 PM
Solved it myself folks :)
Here's the solution:
public GUISkin myGUISkin;
private GUIStyle myStyleBtnFog;
void OnGUI()
{
GUI.skin = myGUISkin;
RenderSettings.fog = GUILayout.Toggle(RenderSettings.fog, "", myStyleBtnFog);
}
void Start () {
myStyleBtnFog = new GUIStyle(myGUISkin.toggle);
myStyleBtnFog.normal.background = (Texture2D)Resources.Load("GUITextures/ButtonLightNormal");
myStyleBtnFog.onNormal.background = (Texture2D)Resources.Load("GUITextures/ButtonLightOnNormal");
myStyleBtnFog.hover.background = (Texture2D)Resources.Load("GUITextures/ButtonLightHover");
myStyleBtnFog.onHover.background = (Texture2D)Resources.Load("GUITextures/ButtonLightOnHover");
}