So i’m creating an augmented reality app that let’s me place augmented furniture in a scene and im trying to create buttons that let me change the color of the furniture at runtime.
Furniture model has a meshrenderer component which has only 1 material (colored red)attached to it.
i’m trying to change it to a specific color by clicking a button which calls a method that changes the original red color to that specific color (let’s say blue).
I tried changing the color of the material of the models using this code:
public void ChangeColorToBlue()
{
Renderer rend = SelectedObject.GetComponent<Renderer>();
rend.material.shader = Shader.Find("Standard");
Color blue = new Color(0, 0, 255);
rend.material.SetColor("_Color",blue);
}
i also tried something like this.
public void ChangeColorToBlue()
{
MeshRenderer rends = SelectedObject.GetComponent<MeshRenderer>();
Material[] mats = rends.materials;
mats[0].color = Color.blue;
rends.materials = mats;
}
both of them did not work. i don’t know where the problem is.
i’m hoping someone could help me.
thank you in advance.