Search Unity

Change Color / Alpha

Discussion in 'Scripting' started by devel, Apr 7, 2009.

  1. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    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??
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    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.
     
  3. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    Excellent, thanks!
     
  4. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    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?
     
  5. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    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