- Home /
Fading an object via script
How would you fade out an object via script? I've got a cube that needs to completely disappear - slowly fading out, not just turning off the rendering. I tried the example from the documentation, but it doesn't seem to do the trick. The cube just disappears instantly; not the effect I was looking for. Here's the code I have currently:
var colorStart = Color.red; var colorEnd = Color.green; var duration = 1.0;
function Update () { var lerp = Mathf.PingPong (Time.time, duration) / duration; renderer.material.color = Color.Lerp (colorStart, colorEnd, lerp); }
It's directly copied from the docs but won't fade over time - it's instantaneous. I would appreciate a pointer or two.
Thanks in advance - Elliot Bonneville
Answer by Eric5h5 · Mar 15, 2010 at 09:06 PM
You need to use a transparent shader, not a transparent cutout shader (which is what I'm guessing you're using).
Your answer
Follow this Question
Related Questions
Mesh Filter 8 Answers
Disable GameObject Only Father Not Children 2 Answers
get all scripts attached to gameobject 2 Answers