change all materials color back to original
I have different materials with different color for each gameobject. manage to change all materials color but didn't manage to revert them back to their original state. the objects revert back to full black color. cant find the cause of this. here's an example script:
private Color originalColor;
void Start()
{
foreach(Material mat in this.gameObject.GetComponent<Renderer>().materials)
{
mat.color = originalColor;
}
}
void OnCollisionEnter(Collision other)
{
foreach(Material mat in this.gameObject.GetComponent<Renderer>().materials)
{
mat.color = color.grey;
}
}
void OnCollisionExit(Collision other)
{
foreach(Material mat in this.gameObject.GetComponent<Renderer>().materials)
{
mat.color = originalColor;
}
}
Answer by Zynek · Nov 07, 2016 at 09:02 AM
Are you initializing the originalColor ? if not it most likely is black.
sorry typed wrongly. its supposed to be originalColor. but it still remains black.
I get that and the script seems fine, except that you´re not setting the proper originalColor anywhere.
sorry don't really get by what you meant. how do I set the proper originalColor? doesn't those in start() already set the originalColor?
oh my bad. tried, but all materials color only return to the first material color and not accordingly.