Using lerp and alpha

Hi im having a slight difficulty in fading several objects at once…

Im using this script with the new beta :

/*another function*/
for (var child : Transform in initiateCrack.transform) {
        (child).gameObject.AddComponent ("Rigidbody");
        fadeColors((child).renderer);
    }
/*end of other function*/
function fadeColors (objectRenderer) {

    while (objectRenderer.material.color.a > 0.1) {
        var fadeColor : Color = objectRenderer.renderer.material.color;
        fadeColor.a = 0.0;
        objectRenderer.renderer.material.color = Color.Lerp (objectRenderer.renderer.material.color, fadeColor, 0.1* Time.deltaTime);
        yield;
    }
}

I though the alpha thing was to be resolved in this build? Or am I doing something wrong? Im using a aplha/glossy shader on the “child” objects…

When I try it it simply turns to 0, no fade!

You are trying to use yield in fadeColors but you need to call it through StartCoroutine in order for that to work.

I.E.
instead of:
fadeColors((child).renderer);
use:
StartCoroutine(“fadeColors”, (child).renderer);

See:

and

EDIT: Changed the StartCoroutine call. I don’t like bad code lying around. :slight_smile:

ah I knew about that actually, thanks for pointing ithat out!
I edited your code to please the compiler :wink:

StartCoroutine ("fadeColors","((child).renderer)");

Hmm… Can’t find variable material?

    for (var child : Transform in initiateCrack.transform) {
        (child).gameObject.AddComponent ("Rigidbody");
        StartCoroutine ("fadeColors","((child).renderer)"); 
    }
//---------------------------------
function fadeColors (objectRenderer) {

while (objectRenderer.material.color.a > 0.1) { 
        var fadeColor : Color = objectRenderer.material.color; 
        fadeColor.a = 0.0; 
        objectRenderer.material.color = Color.Lerp (objectRenderer.material.color, fadeColor, 0.1* Time.deltaTime);
        yield; 
    } 
}

Feel free to use this JS if it helps you out:

var initialDelay = 1.0;
var fadeSpeed = 0.1;

yield new WaitForSeconds(initialDelay);

StartCoroutine("Fade");

function Fade()
{
	while (renderer.material.color.a > 0.004)
	{
		color = renderer.material.color;
		color.a = 0.0;
		renderer.material.color = Color.Lerp(renderer.material.color, color, fadeSpeed * Time.deltaTime);
		
		yield;
	}
	Destroy(gameObject);
}

I did :smile:

hh