Question by
kyko0 · Jul 03, 2018 at 09:38 AM ·
materialscript.renderercolor change
renderer material color changing with script ??
Hii ! I am having some issues with changing the color of a material by scripting i'm creating a cube .
i wrote this code : void Update () { gameObject.GetComponent().material.color = Color.blue; }
but it doesn't work ??
thank you !
Comment
Do you have any error in the console?
Are you sure you have attached the script to an active gameObject in your scene?
Are you sure the gameObject has a Renderer attached?
Are you sure you have provided a material supporting color tinting?
Answer by tormentoarmagedoom · Jul 04, 2018 at 08:03 AM
Good day.
You are not accessing any component. Do this
gameObject.GetComponent<MeshRenderer>().material.color = Color.blue;
Bye!