mardi 2 août 2016

How to test what material is applied to an object in Unity

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

Aucun commentaire:

Enregistrer un commentaire