Changing gameObjects material on trigger?

I am playing around in Unity and trying to learn the coding. I am using C#. I am somewhat familiar with it.

I am trying to set up a trigger that will change the material on a cube with this code :

void OnTriggerExit(Collider Player) {
	GameObject.Find ("Cube").rigidbody.useGravity = true;
	GameObject.Find ("Cube").renderer.material = Spark;

The useGravity works fine. But the problem with changing the material to a new material is that the new material is not exist in that context. So how do I solve this? How do I get access to the materials in when programming?

You need to initialize the Spark material in your code to access it.

Try adding this to your code:

public Material spark;

Then just drag your material into the script.