[CLOSED]Unity 5 GameObject.Renderer.Material

Did something changed on Unity 5 ?

I know how to do this another ways but I don’t know why this is not working:

I’m trying to change the GameObject color using


but it gives error :
“error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement”

**EDIT: UNITY changed this, now to use ‘gameObject.renderer.material’ you need to change to


Thats my entire code:

using UnityEngine;
using System.Collections;

public class RiftRay : MonoBehaviour {
	public LayerMask mask;
	public GameObject[] pisos;
	public int distance;
	void Update () 
		Vector3 fwd = transform.TransformDirection(Vector3.forward);
		Debug.DrawRay(transform.position, fwd, Color.green);
		if (Physics.Raycast(transform.position, fwd, distance ,mask ))
				pisos[0].renderer.material.color = Color.black;

GetComponent().material.color = Color.black;

Try this

cesarureno’s answer didn’t work for me. just this one:

GetComponent<Renderer>().materials[0].color = Color.Black;

That’s nothing to do with Unity 5; that’s just bad code. Line 19 should read:

pisos[0].renderer.material.color = Color.black;

Unity - Scripting API: Renderer.material GRR Unity