- Home /
Question by
bibikonfikus1234 · May 26 at 04:21 PM ·
sharedmaterial
Shared Material is changing???
I want change object color, when mouse cursor on object.
private void OnMouseEnter()
{
for (int i = 0; i < renderers.Length; i++)
{
renderers[i].material.color = new Color(renderers[i].material.color.r * coef, renderers[i].material.color.g * coef, renderers[i].material.color.b * coef);
}
}
private void OnMouseExit()
{
for (int i = 0; i < renderers.Length; i++)
{
renderers[i].material = renderers[i].sharedMaterial;
}
}
When OnMouseEnter call, material color change, but when OnMouseExit call, nothing happens.
Comment
Answer by jeromeatunity · May 26 at 10:37 PM
Hello. This is working as expected. See this post that explains the link between Renderer.material and Renderer.sharedMaterial. The best way would be to cache the original color and use that value in OnMouseExit. See this post.
Your answer
Follow this Question
Related Questions
Can't set sharedmaterials 1 Answer
How to set second material to a second submesh in a combined mesh? 0 Answers
more efficient = gameObject w. Material[5] or 5x GameObject w. material[1] 1 Answer
How can we use two different material on a same game object at the same time? 2 Answers
How to share material between meshes 1 Answer