Fading 3d text - only fades once

Hello all, first off thanks in advance.

But I have looked at how to do this on many forum posts and I think I created the code correctly. The issue is it seems to fade over say 2 seconds once without issue but from then on it will just have a 2 second delay and blink on or off. The goal of the code is to fade in and out at a certain range from the camera… Seems simple but I have no idea what would cause this to just work once and stop after that… Any help would be greatly appreciated. Thanks again.

Script on 3d text:

var Range = 30.0;
var target : Transform;
var _time:float;

function Update ()
{
   if (Vector3.Distance(transform.position, target.position) > Range){
       Fade.use.Alpha(GetComponent(TextMesh).renderer.material,1.0,0.0,_time, EaseType.In);
	}

if(Vector3.Distance(transform.position, target.position) < Range){
       Fade.use.Alpha(GetComponent(TextMesh).renderer.material,0.0,1.0,_time, EaseType.Out);
	}
}

Script on Fade.js:

function Awake () {
    if (use) {
        Debug.LogWarning("Only one instance of the Fade script in a scene is allowed");
        return;
    }
    use = this;
}

function Alpha (object : Object, start : float, end : float, timer : float) {
    yield Alpha(object, start, end, timer, EaseType.None);
}

function Alpha (object : Object, start : float, end : float, timer : float, easeType : EaseType) {
    if (!CheckType(object)) return;
    var t = 0.0;
    var objectType = typeof(object);
    while (t < 1.0) {
        t += Time.deltaTime * (1.0/timer);
        if (objectType == GUITexture)
            (object as GUITexture).color.a = Mathf.Lerp(start, end, Ease(t, easeType)) * .5;
        else
            (object as Material).color.a = Mathf.Lerp(start, end, Ease(t, easeType));
        yield;
    }
}

function Colors (object : Object, start : Color, end : Color, timer : float) {
    yield Colors(object, start, end, timer, EaseType.None);
}

function Colors (object : Object, start : Color, end : Color, timer : float, easeType : EaseType) {
    if (!CheckType(object)) return;
    var t = 0.0;
    var objectType = typeof(object);
    while (t < 1.0) {
        t += Time.deltaTime * (1.0/timer);
        if (objectType == GUITexture)
            (object as GUITexture).color = Color.Lerp(start, end, Ease(t, easeType)) * .5;
        else
            (object as Material).color = Color.Lerp(start, end, Ease(t, easeType));
        yield;
    }
}

function Colors (object : Object, colorRange : Color[], timer : float, repeat : boolean) {
    if (!CheckType(object)) return;
    if (colorRange.Length < 2) {
        Debug.LogError("Error: color array must have at least 2 entries");
        return;
    }
    timer /= colorRange.Length;
    var i = 0;
    var objectType = typeof(object);
    while (true) {
        var t = 0.0;
        while (t < 1.0) {
            t += Time.deltaTime * (1.0/timer);
            if (objectType == GUITexture)
                (object as GUITexture).color = Color.Lerp(colorRange_, colorRange[(i+1) % colorRange.Length], t) * .5;_

else
(object as Material).color = Color.Lerp(colorRange*, colorRange[(i+1) % colorRange.Length], t);*
yield;
}
i = ++i % colorRange.Length;
if (!repeat && i == 0) break;
}
}

private function Ease (t : float, easeType : EaseType) : float {
if (easeType == EaseType.None)
return t;
else if (easeType == EaseType.In)
return Mathf.Lerp(0.0, 1.0, 1.0 - Mathf.Cos(t * Mathf.PI * .5));
else if (easeType == EaseType.Out)
return Mathf.Lerp(0.0, 1.0, Mathf.Sin(t * Mathf.PI * .5));
else
return Mathf.SmoothStep(0.0, 1.0, t);
}

private function CheckType (object : Object) : boolean {
if (typeof(object) != GUITexture && typeof(object) != Material) {
Debug.LogError("Error: object is a " + typeof(object) + “. It must be a GUITexture or a Material”);
return false;
}
return true;
}

You’re starting a new instance of the Fade routine every frame. You should call it once only, until it’s finished. Either don’t use Update (e.g., use a trigger with OnTriggerEnter/Exit), or else add logic so that it’s only called once when needed and not every frame.