- Home /
Question by
Buzz Hsu · Jun 28, 2015 at 01:13 PM ·
materialeditor-scriptingassets
Assign sharedMaterials from assets with editor script.
Apologize for my poor English, forgive me please. I'm working on a hex tile map editor, and I need to assign materials to tiles. I found out I cannot assign the materials one by one, like what other people do on their post. The assigned material never shows up.(not even in the inspector) But if I assign an array, the problem solved. I suspect it has something to do with assign by value, but nor sure about it. I'd like to hear some explanation. thanks!
// this region doesn't work:
// Material temp;
// temp = AssetDatabase.LoadAssetAtPath("Assets/Materials/"+tData.TerrainDBIndex+"top.mat",typeof(Material))as Material;
// renderer.sharedMaterials[0] = temp;
// temp = AssetDatabase.LoadAssetAtPath("Assets/Materials/"+tData.TerrainDBIndex+"side.mat",typeof(Material))as Material;
// renderer.sharedMaterials[1] = temp;
// this region work:
Material[] temp;
temp = new Material[2];
temp[0] = AssetDatabase.LoadAssetAtPath("Assets/Materials/"+tData.TerrainDBIndex+"top.mat",typeof(Material))as Material;
temp[1] =AssetDatabase.LoadAssetAtPath("Assets/Materials/"+tData.TerrainDBIndex+"side.mat",typeof(Material))as Material;
renderer.sharedMaterials = temp;
Comment