- Home /
lerp transparency
What would be the best way to lerp transparency like color http://docs.unity3d.com/Documentation/ScriptReference/Material-color.html
so it fades in and out continuously, I thought it would be something like
var duration : float = 1.0;
var lerp : float = Mathf.PingPong (Time.time, duration) / duration;
startText.renderer.material.color.a = Color.a.Lerp (0, 1, lerp);
Answer by Griffo · Oct 11, 2012 at 06:04 AM
Done it ..
#pragma strict
var duration : float = 1.0;
var alpha : float = 0;
function Update(){
lerpAlpha();
}
function lerpAlpha () {
var lerp : float = Mathf.PingPong (Time.time, duration) / duration;
alpha = Mathf.Lerp(0.0, 1.0, lerp) ;
renderer.material.color.a = alpha;
}
Answer by refardeon · Oct 10, 2012 at 07:44 PM
Make sure the shader you're using is a transparent shader; see the material settings in the inspector.
Oh, and if I recall correctly, .material.color.a is read-only, you'll have to use a temporary variable to modify the .a component.
Griffo is using Unityscript, so you don't need to make temporary variables. Assigning to color.a is fine.
Oh, I didn't remember that. It's been a while since I switched to C# :)
Your answer
Follow this Question
Related Questions
make a gameobject lerp transparency? 2 Answers
Change alpha value to transparent when colliding 1 Answer
changes to colour alpha affect RGB values, but not in the same way 1 Answer
glass sphere with reflective/specular shader? 2 Answers
How do you get ambient occlusion working with transparency and lightmapping? 0 Answers