How to get material component in script?

Hello,

I need to access my GameObject's Material Component settings through scripting, and using methods like: myMaterial = GetComponent(Material);

aren't working out for me. Any suggestions?

Thanks!!

Material isn't a component, it's a class used with Renderer.

var myMaterial = renderer.material;

update (since the renderer property got deprecated)

var myMaterial = GetComponent<Renderer>().material;

You can load your material directly from the library:

Material myMaterial = Resources.Load("Materials/MyMaterial", typeof(Material)) as Material;

The answer is now:

GetComponent().material.