Renderer.material alternative?

selectedTarget.renderer.material.color = Color.red;

Just following along on a tutorial, I get this error.

‘UnityEngine.Component’ does not contain a definition for ‘material’ and no extension method ‘material’ accepting a first argument of type ‘UnityEngine.Component’ could be found

Just thought I’d pop this in here.

renderer is no longer a property of MonoBevaiour, we did some cleaning up.
do this:

selectedTarget.GetComponent().material

2 Likes

What will be the selectedTarget?

selectedTarget looks like it’s a variable the OP made that represents the GameObject that they want to access the material on.

So, really it could be any Game Object that has a renderer attached to it.