How do I get the current alpha value of a material?

I’ve got a GUIText that I’m trying to get the current alpha value of before I start a fade. I’m having trouble with the code below always returning 0.

public float CurrentMessage1Alpha;
	void Update () {
	GameObject Message1 = GameObject.Find("Messages1");
	CurrentMessage1Alpha = Message1.guiText.material.color.a;
	}

What am I doing wrong?

I believe you get to the material by accessing the GUIText's transform's renderer...

Like this:

 if ( Message1.guiText.transform.renderer != null ) {
     print(Message1.guiText.transform.renderer.material.color.a);
 }

OR...

After looking at the documentation some more, it looks like you might want to try the GUIText.renderer if that doesn't work...

if ( Message1.guiText.renderer != null ) {
    print(Mesasge1.guiText.renderer.material.color.a);
}

I've never used a GUIText, but I'm pretty sure one of those will work.

Are you sure your alpha value isn't actually equal to 0?

I just created a GUIText in my game to test this...

First I added a material to the GUIText in the Inspector.

Then I added the following script to the object with the GUIText attached:

function Update () 
{
    var theTex  :  GUIText = transform.GetComponent(GUIText);

    var theMat  :  Material  =  theTex.material;

    Debug.Log("Material " + theMat.name + "has alpha " + theMat.color.a);
}

It prints the name of my material and the value 1 over and over.

This makes me wonder... Is your value actually 0?