- Home /
render.material.color is not working, or at least not completely?
I'm been working on a game in unity and I'm currently working on the main menu. To start I put some 3d Text in the scene for selections in the menu, wrote a script so when they are clicked they take you to the appropriate destination (play goes to the game, options goes to options etc.). Next I wanted to make it so the text would change color when the mouse would hover over it. This is where I encountered a problem. If the text's orginal color was white it would change back and forth just fine. However if the text was a different color other than white (red for example), the color would become a "mix" of the two. For example, I wanted some red text to become yellow when highlighted and it became an orange. The color displayed in the inspector for the material would however changed as expected. I was using Color so I changed it to Color32, however that did nothing. Here is my code that changes the color:
void OnMouseEnter(){
renderer.material.color = Color.yellow;
}
void OnMouseExit(){
renderer.material.color = Color.red;
}
Could it just be my monitor? Or is it an error with the editor itself? Answers are appreciated! Thanks!
How the material color is handled (or not handled at all) depends on the shader. You might find a shader to do what you want, but most shaders overlay the color you specify on the existing color.
I have the same problem. Did you manage to solve your issue? I would really appreciate it if you could share your solution.
Answer by SPIGS · Jan 02, 2014 at 08:09 PM
As I stated in my question my problem was modifying the color of some 3d text (or just text in general). Instead of modifying the material itself (as I did when I asked the question), modify the Text Mesh color like so:
void OnMouseEnter ()
{
GetComponent<TextMesh> ().color = Color.yellow; // For 3D Text
GetComponent<GUIText>().color = Color.yellow; // For GUI Text
}
I couldn't replicate what I did when I asked the question (the colors mixing). They may have changed something in 4.3, but anyways when dealing with text modify the Text Mesh rather than the material itself.