- Home /
How to create a complex material in an Editor-Script? C#
Hi, I created an Editor-Script which takes the materials of an GameObject and replaces them by existing materials from the Resources-Folder. Now I want my script to replace the old materials by new materials which I create in the script! I got this fare:
GameObject SelectedObject = Selection.activeGameObject;
Material[] materials = SelectedObject.GetComponent<Renderer> ().sharedMaterials;
int Arraylength = materials.Length;
for (int i = 0; i < Arraylength; i++) {
string matName = materials [i].name;
if (matName == "Test_Material_01") {
int var = i;
Material mat = new Material (Shader.Find("Standard"));
AssetDatabase.CreateAsset(mat, "Assets/Imports/Object/Materials/NewMat_" + var + ".mat");
materials [var] = mat;
SelectedObject.GetComponent<Renderer> ().sharedMaterials = materials;
...
This code creates a new white Standard-Shader and saves it!
The Problem: I don´t know how to build more complex Standard-Shaders in this script. With textures, colors, smoothness, metallic look and so on...
Can anybody help? Thank you!!
Comment