Search Unity

How do I control the alpha of an object, via jscript?

Discussion in 'Scripting' started by ruibjr, Feb 24, 2010.

  1. ruibjr

    ruibjr

    Joined:
    May 30, 2009
    Posts:
    43
    Hi.
    How can I change the opacity (alpha) of an object, via JavaScript?
    The Transform for that object is in variable tgt.
    But I haven't found the proper way to access its color.alpha - I am not even sure that is the way to do it.
    The object is already employing the Transparent Diffuse mode, so I can actually change the alpha channel manually and it displays beautifully on the screen.
    Now, I need to control that same alpha channel, just in JavaScript, instead of manually.

    Thanks.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    renderer.material.color.a = x

    Where x is between 0 and 1.

    --Eric
     
  3. ruibjr

    ruibjr

    Joined:
    May 30, 2009
    Posts:
    43
    Thanks a lot!