Fade 3d text with lerp?

Hello!


I want the Main Menu 3D Texts to slowly fade out when the user hits play.
I used this script but unfortunately it makes the letters black, not transparent.

Any help?


#pragma strict
var buttonState : int = 1;
var click : AudioClip;
var LevelToLoad : String;

var quitButton : GameObject;
var title : GameObject;

var lerpedColor : Color = Color.white;
private var stop : boolean;


function OnMouseEnter () {
	if(!stop)
	{
		renderer.material.color = Color.blue;
		audio.PlayOneShot(click);
	}
}

function OnMouseExit () {
	if(!stop)
	{
		renderer.material.color = Color.white;
	}
}

function OnMouseUp () {
	if(buttonState == 1)
	{
		Camera.main.animation.Play();
		stop = true;
		//Application.LoadLevel("LevelToLoad");
	}
	else if(buttonState == 2)
	{
		Application.Quit();
	}
}

function Update () {
	if(stop)
	{
		lerpedColor = Color.Lerp(Color.white, Color.black, Time.time);
		renderer.material.color = lerpedColor;
		quitButton.renderer.material.color = lerpedColor;
		title.renderer.material.color = lerpedColor;
	}
}

@hiddenspring81:

Have you tried changing it tolerpedColor = Color.Lerp(Color.white, Color.clear, Time.time);

this is wrong for two reasons, first lerping goes from the current value to the target value, and assign the result to current in order to linearly move (hence the name lerp). What you propose is to get the difference between white and black and assign the difference to the value. Second, your ratio is Time.time which means after 1s you have full move at once. Only during the first second can you see the interpolation.

Here is how you do it:

void Update () {
  Color col = renderer.material.color;
  col.a = Mathf.Lerp (col.a,0f,0.01f);
  renderer.material.color = col;
}

This is greatly simplified and should be put in a function for control, but the idea that you get the color and modified the a for alpha transparency. Lerp will get from the value of a which should be 1 down to 0 with a ratio of 0.01 per frame. As a result you will never really get down to 0 so you would probably favor something like:

void Update(){
  ratio += Time.deltaTime;
  Color col = renderer.material.color;
  col.a = Mathf.Lerp (col.a,0f,ratio);
  renderer.material.color = col;
}

This will interpolate over 1second. Adding a multiplier to ratio allows you to control the period of time, use < 1 for increasing time and > 1 to reduce time.

Note you can also use Color.Lerp.