Change Color / Alpha

I have two questions with regard to fading in out / changing the alpha value over time:

1.) FadeIn/Out a GUITexture:

I would like to fade in / out a GUITexture on a certain event. So I have found the JS FadeIn-Script
(http://www.unifycommunity.com/wiki/index.php?title=FadeIn) and would like to modify it a bit and make it C#.

Now in C# when I type

guiElement.color = Color.red;

I get the following error:
‘UnityEngine.GUIElement’ does not contain a definition for ‘color’
→ What would be the C# equivalent for this??

2.) Change color/alpha of a Plane:
In the Start()-function I set the color of the plane to which the script is applied:

renderer.material.color = new Color(1,0,0,a);

The color is set fine (I have tried with several), though the alpha value has no impact (plane is always opaque)
→ Why??

  1. .color is a member of GUIText and GUITexture, but not of GUIElement. Try guiTexture.color instead.

  2. The plane must have a shader that supports transparency. You’re probably using the default Diffuse shader, which doesn’t.

Excellent, thanks!

1.) I get the same errors for GUIText as well as GUITexture.

Furthermore “guiElement.color = Color.red” does work in JavaScript → so it should work in C# also.

Any ideas?

Well, no, it shouldn’t…that uses dynamic typing, which C# doesn’t have. guiElement is obsolete anyway (as I believe the warning tells you).

–Eric