Fade in fade out text

pls help me i want to fade in and fade out my texture like other rpg game thanks for your help!

var tex: Texture;
var _timeOfFade:float=0;
var delta:float;
var postion: Rect;
private var _color:Color=Color(1.0f,1.0f,1.0f,1.0f);

function start()
{
}
function Update () {
	
	delta=(1/_timeOfFade)*Time.deltaTime;

	//print(delta);
}

function OnGUI()
{
	if(_color.a>0){
		_color.a-=delta;
		GUI.color=_color;
		GUI.DrawTexture(postion, tex, ScaleMode.ScaleToFit, true, 10.0f);
	}
}

The above code will work if u copy it some new file and link it to a gameObject(attach the texture u want to display and also the position rectangle and time of fade in the editor after attaching the script), but i suggest you to use this only as a reference and create ur own!!

Btw this is done in javascript! IF u r new go with javascript, that will be easy to start with.

see simple copy and paste all the script below into a new file named “fade”

//Fade File

enum EaseType {None, In, Out, InOut}
static var use : Fade;

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;
}
after pasting it in a file, create a script of any name and attach it to ur textMesh.
Copy and paste the below code into it and attach it to a game object(i prefer camera),
var _time:float;
var b=false;

function Update () {

* if(b==false)*
* {*
* b=true;*
* Fade.use.Alpha(renderer.material,1.0,0.0,time);
_
}*

}
and give the time in editor, u will get the fade effect!.. it worked for me. jus try it will work for u too!!..
and if u want to change something, dont do it in fade file.
do it in ur code!!