How to set the material of an object?

I’m very new to Unity, but was trying to run this code when a button is pressed:

public void onButtonPress(Material m){

	this.Material = m;

}

It doesn’t work though. I tried looking to see if there was some sort of setMaterial() function, but could not find one

In general, how should one go about trying to find the proper functions to do things like this, when there are so many to choose from?

It’s even more straightforward that you think it is; you just need to set the material of that object equal to ‘m’.

gameObject.GetComponent<MeshRenderer>().material = m;

If you ever need to refer to the GameObject that the script is running on, just use ‘gameObject.’
GetComponent is your friend as far as finding/using the components attached to that object.

gameObject.GetComponent().material = m;