How to assign a GUISkin using code only?

Hi, I have made an editor script that creates an object with an assigned script. Unfortunately, that object will always have an empty GUISkin, so I have to assign it by inspector, which is really inefficient as I’m going to start using hundreds of these objects.

Is there anyway to assign a GUISkin without the use of the inspector, via javascript coding?

Like: = GetAsset(“MainSkin”);

At edit-time, you can use Resource.LoadAssetAtPath(). Example:

    mySkin = Resources.LoadAssetAtPath("Assets/MySkin", GUISkin) as GUISkin;

At run-time, put your GUISkin somewhere under any folder named Resources, and use Resources.Load(). Example: = Resources.Load("Skins/MyGUISkin") as GUISkin;

In practice, check the return value for null first. The load could have failed.