Increasing the alpha of a material gradually

I have this script which is supposed to make the target become visible gradually:

enum Action {
	Appear_and_Solid = 1
}

var Target : GameObject;
var Select : Action;

function OnTriggerEnter (collision : Collider) {

	if (collision.gameObject.FindWithTag ("Player")) {
	
		switch (Select)
		{
		case 1:
			for (var i : float = 0.0f; i < 1; i = i + 0.0005) {
				Target.renderer.material.color.a = i;
				Target.GetComponent(BoxCollider).enabled = true;
			}
			break;
		default:
			Debug.Log ("No action!");
			break;
		}
		
	}
}

Instead, it just appears instantly. What’s wrong?

In the line:

for (var i : float = 0.0f; i < 1; i = i + 0.0005)

use:

for (var i : float = 0.0f; i < 1.0f; i = i + 0.0005f)

That didn’t change anything.

sorry, try this:

enum Action {

    Appear_and_Solid = 1

}

 

var Target : GameObject;

var Select : Action;

var appear : boolean = false;
var StartTime : float;

function FixedUpdate (){

	if(appear){
		var temp = Target.renderer.material.color;
		temp.a = Mathf.Lerp(0.0f, 1.0f, (Time.time-StartTime)/5);
		Target.renderer.material.color = temp;
		if(temp.a == 1.0f){
			appear = false;
		}
	}

}

function OnTriggerEnter (collision : Collider) {

 

    if (collision.gameObject.FindWithTag ("Player")) {

    

        switch (Select)

        {

        case 1:

            StartTime = Time.time;
            appear = true;

            break;

        default:

            Debug.Log ("No action!");

            break;

        }

        

    }

}

Note: be sure your material is transparent

Aha, delaying is missing here. There is no need for changing the whole code. It turns out that there were NO delay for the “for” loop. Adding “yield;” solved the problem.