If statement will not return true

using UnityEngine;
using System.Collections;

public class GreenWall : MonoBehaviour {
public GameObject Player;
public Material Green;
public bool activeGreen = false;

		
	void Update () {
		
	if (Player.gameObject.renderer.material == Green)
		activeGreen = true;
	}
	
	void OnCollisionEnter(Collision collision) {
		if (collision.gameObject.name == "Player" && activeGreen == true)
			transform.Translate (new Vector3(3,0,0));
	
	}
}

I am trying to check if the Player’s material is called Green and if so return true on ‘activeGreen’ but for some reason the IF statement would not return true.
I have checked the rest of the code by forcing activeGreen to be true and everything works, so I guess the problem lies in the IF statement.
I have done this code with just color instead of material and it works fine. I am at a bit of a loss.

Any help would be appreciated! Thank you

I don’t see anywhere you actually assign the material called Green.

You are checking for a material not a colour.
If you use color Green, in this case Green is a predifined Color.

By using public Material Green; you have created a Material instance called green, but as I say you have not assigned it.

renderer.material.color = Color.green;

will change the color of the material to green.

http://docs.unity3d.com/Documentation/ScriptReference/Renderer-material.html

It appears that you are trying to access the base or SharedMaterial rather than the instance that is assigned to the renderer. Keep in mind, that each object can use the same SharedMaterial, but the material property can be manipulated at runtime so that it only affects a certain object. Make this small change to the code and see if this helps:

void Update () {
 
    if (Player.gameObject.renderer.sharedMaterial == Green)
       activeGreen = true;
    }

NOTE: I’m assuming that you are assigning the value of the class member “Green” in the inspector for this to work.

public GameObject Player;

public Material Green;

set both var correctly