- Home /
Why is 'material.color = Color.grey' turning all my sprites in my game grey?
When the music button is disabled in my game I want the button to turn grey. Using the code below turns the button grey but it also turns all of my other sprites using the same material grey as well. How can I fix this so that only the musicButton material turns grey?
public Button musicButton; // Set in inspector
...
musicButton.image.material.color = Color.grey;
Comment
Best Answer
Answer by Addyarb · Jan 29, 2015 at 12:18 AM
Editing an object's material doesn't just edit that object's material. It's sort of counter-intuitive, but that's how it works. It will edit the material for every single object that shares the material as well.
To fix this, you must make a unique material by right-clicking and Create>Material. Then apply that material to your sprite. Now your script should only turn that object's material grey.