- Home /
 
I'm trying to change a material, texture or color and it doesnt work
I had no problem with an older version of unity switching the texture.
I used:
 renderer.material.mainTexture = dice1;
 
               It had worked just fine until unity 5. I run it in unity 5. It corrects the code.
 GetComponent.<Renderer>().material.mainTexture = barcolor1;
 
               then it tells me that it doesn't work because there isn't a renderer attached. But there is a renderer attached. I change the code and it tells me the syntax is incorrect. Like it tells me there is no semicolon....but there is a semicolon!
I've tried all sorts of ways. The compiler hates me. I have an alternate solution, but it doesn't solve other issues I will have in the future, or its a real round about way.
$$anonymous$$ods: Has the syntax for GetComponent changed in Unity 5?
 // Shouldn't GetComponent.<Renderer>() be GetComponent<Renderer>() ?
 
                  // uJS
 GetComponent.<Renderer>()
 // C#
 GetComponent<Renderer>()
 
                  //Yes, it is GetComponent<Renderer>()
 
                  Edit: my mistake, only for C#
As long as barcolor1 is a Texture, there is nothing wrong with the code you posted. You may have an error somewhere else. If you delete that line of code, does the error go away?
Your answer