- Home /
Assign myGUISkin in javascript
Hi,
I want to assign my own GUISkin to the GUI.skin in javascript. Till now I have written this code (shown bellow) but I don't know how to assign myGUISkin = the GUI skin I created in the inspector.
So, the whole context is like this: the GUISkin I created is called "EsGUIskin.guiskin" and I have it in my project folder.
And in a script I have written:
var myGUISkin : GUISkin;
BUT HOW do I SAY THAT myGUISkin=EsGUIskin.guiskin?????
function OnGUI () {
GUI.skin=myGUISkin;
//whatever here }
Thanks in advance,
Answer by Uzquiano · Mar 19, 2011 at 06:39 PM
So after many tries, I thought (with my head) and the solution is as simple as this, code shown below:
var myGUISkin : GUISkin;
function Start () { myGUISkin = Resources.Load("EsGUIskin"); }
function OnGUI () {
GUI.skin = myGUISkin;
GUI.Box (Rect (10, 10, 100, 20), "Espaol o");
GUILayout.Box ("Espaol o");
}
Cheers
Answer by Eric5h5 · Mar 19, 2011 at 05:28 PM
Just drag the skin onto the slot in the inspector.
Please, I want to do it in my SCRIPT (javascript). I already know the drag-and-drop solution... If it is not possible just say to me please.
It wasn't clear that you knew about drag-and-drop. You can use Resources.Load, but I'd recommend using drag-and-drop unless you have good reason not to.
Thanks anyway Eric5h5, for helping me and others. I am improving quite fast in Unity scripting thanks to your and others help.
And yes, I do have reasons for using javascript as much as possible ;)
Answer by lcn75 · Dec 20, 2011 at 07:45 AM
Hi, try this...(the name of my skin is 'My Skin' in the 'Assets/SKIN' folder).
var myCustomSkin : GUISkin;
function Start () {
myCustomSkin = Resources.LoadAssetAtPath("Assets/SKIN/MySkin.GUISkin", GUISkin);
}
function OnGUI () {
GUI.skin = myCustomSkin;
}
In documentation there is: "Returns a resource at an asset path (Editor Only).", so after building standalone version it can couse problems. It's better to use 'Resources.Load' ins$$anonymous$$d.