How to test what material is applied to an object.
I have a diamond-sprite and I want to be able to change the colour of the diamond from white, it's original colour to green. However, I can not figure out how to do this.
public class MoveControl : MonoBehaviour {
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.A) )
{
if (GetComponent<Renderer>().material.color == Color.white)
{
GetComponent<Renderer>().material.color = Color.green;
}
}
}
}
This above code is what I have right now and it only works if the material applied to the sprite, being white, is a sprites/default shader. This may not sound like a big problem but whenever I apply a different material of a different colour, such as blue, and change its settings so it has a sprites/default shader, the sprite becomes invisible.
I'm new at Unity and if someone could help me out, it would be very much appreciated.
I also tried removing the material and just alter the sprite renderer colour itself to see if my problem would be solved. The code worked if the sprite was white but did not work as soon as I changed the colour to blue.
Your answer
Follow this Question
Related Questions
Material Mixing Colors? 1 Answer
Model with many details require many textures. How to make it? 0 Answers
Get Component isn't working too well 1 Answer
Why do dots appear on pbr materials when I use iOS Platform module?, 1 Answer
How to apply a fade in transparency to objects that have materials that reference images 0 Answers