|
Hi, I know how to create a temp material for a game object, but is it possible to create a new asset within a script? I want to be able to do this as part of an editor script I'm writing. Thanks Steve
(comments are locked)
|
|
Check out AssetDatabase.CreateAsset - it'll turn an instance of a material into an Asset in the project http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.CreateAsset.html (Even has a material example for you) Thanks Mike, ideal. I also modified it slightly to name the material after whatever is currently selected in the Hierarchy: (I put this in a separate answer because it didn't seem possible to format code in a comment)
Jul 04 '10 at 01:02 PM
Steve Edwards
(comments are locked)
|
I also wanted to then assign the new material to the currently selected object... Selection.activeGameObject.renderer.sharedMaterials = material; but get this error: "Cannot convert UnityEngine.Material to (UnityEngine.Material), which is quite funny as errors go.
Jul 04 '10 at 01:16 PM
Steve Edwards
(UnityEngine.Material) means it's expecting an array of Materials. If you use sharedMaterial instead of sharedMaterials it should work fine
Jul 04 '10 at 02:21 PM
Mike 3
Thanks, that got it.
Jul 04 '10 at 02:45 PM
Steve Edwards
(comments are locked)
|
