- Home /
Question by
mustang4484 · Jun 26, 2018 at 05:12 PM ·
scripting problem
Change two shader color with script
Hi guys I would like to change the color of two material attached to one object, by script. With one material work fine but with two material there is an error on console ("there is no render attached to object...….."). This is my script, I think the problem is on the second Getcomponent on start, can someone help me?
Thank you
public Material torace; public Material costato;
// Use this for initialization
void Start () {
costato = GetComponent<Renderer>().material;
torace = GetComponent<Renderer>().material;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.A))
torace.color = Color.red;
if (Input.GetKeyDown(KeyCode.B))
costato.color = Color.red;
else if (Input.GetKeyDown(KeyCode.S))
costato.color = Color.black;
torace.color = Color.black;
Comment