Fading Out an Object

As my object is about to be destroyed, I want it to fade out smoothly. How can I do this?

var lifeTime = 4.0; var isScaling:boolean = true;

function Update ()
{
    if(isScaling == true)
    {
        Do();
    }
    // Slowly rotate the object around its X axis at 1 degree/second.
    transform.Rotate(20,0,0 * Time.deltaTime);
}

function Do()
{
    transform.localScale += Vector3(.08,.08,.08);
    yield WaitForSeconds(1.0);
    isScaling = false;
    Destroy (gameObject, lifeTime);
}

You can use LeanTween to fade an object, here is an example:

var time:float = 2.0;
var alphaVal:float = 0.0;
LeanTween.alpha(gameObject, alphaVal, time);

Just make sure that the object has a shader that supports transparency! I would recommend Owl Labs Shaders: http://owlchemylabs.com/content/ (Unlit with Alpha);

Download iTween. http://itween.pixelplacement.com/index.php

Use iTween.FadeTo() on your object. I would use it on the line before your yield line, and tell itween to do its job over 0.9f seconds.