What is wrong in this line?

public Color coloroo = renderer.material.color;

i am getting this error ->A field initializer cannot reference the nonstatic field, method, or property `UnityEngine.Component.renderer’

please help

thanks in advance :slight_smile:

public Color color;
// Use this for initialization
void Start () {
color = gameObject.GetComponent().material.color;

Something like this?

1-) Make sure the class is not static. (i.e. not static prefix).

2-) This in-line assignment is better be performed in Start() or Update() or any other method called from those two/from events.