How to make invisible game object with transparent/diffuse with alpha 0 to visible alpha 255 over time
<p>Good day all.</p>

<p>I'm making a tower defense game in Unity3D and I'm trying to create a tower build animation. </p>

<p>So basically, for testing purposes, I have a primitive cube with a material with the transparent/diffuse legacy shader and I've set it's color's alpha to 0 as the tower should be completely invisible when created. It has a Tower script attached to it for the animation. I have another script which deals with the placement of the tower cube.</p>

<p>How do I make a tower completely visible with alpha of 255 of it's material's color when it's created over a certain amount of time?</p>

<p>So if the tower's build time is 5 seconds, the alpha should become from 0 to 255 in 5 seconds.</p>

<p><strong>I've tried the following (Tower.cs):</strong></p>

<pre><code>public float buildTime = 10;

private MeshRenderer mr;;
private Color currentColor;
private bool built = false;

void Start() {
    mr = GetComponent&lt;MeshRenderer&gt;()
    currentColor = mr.material.color;
    StartCorroutine(BuildAnimation());
}

IEnumerator BuildAnimation() {
    float a = 0;
    Color newColor = new Color(currentColor.r, currentColor.g, currentColor.b, a);
    while (!built) {
        mr.material.color = newColor;
        if (a &gt;= 255) {
            built = true;
        }
        a+= 255 / buildTime;
        yield return new WaitForSeconds(255 / buildTime);
    }
}
</code></pre>

<p>Help will really be appreciated, thanks in advance!</p>