Hello, I am trying to color a certain element of a meshrenderer, but with .color, I made several methods, nothing else works
method1
for (int x = 0; x < obj.Length; x++)
{
Color color = obj[x].material.color;
color[2] = redcolor;
obj[x].material.color = color;
}
method2
for (int x = 0; x < obj.Length; x++)
obj[x].material[2].color = redcolor;
It’s not just about coloring, I’m trying to insert a color in the specific element, the setmaterial and material.color works, but the problem I’m having and inserting that color in a specific element
nothing no, it’s just a test I’m trying to do. the element is an int, so I’ll set a value there in the inspector without having to change it every time in the script
So I tried that too, but it works only with material and not with .color
but I haven’t found a solution yet
public MeshRenderer[] obj;
public Color redcolor;
void Start()
{
for (int i = 0; i < obj.Length; i++)
{
Color colors = obj[i].material.color = redcolor;
colors[2] = redcolor;
obj[i].GetComponent<MeshRenderer>().sharedMaterial[2].color = colors;
}