Question by
Seyed_Morteza_Kamaly · Nov 18, 2015 at 06:28 AM ·
unity 5
how FADE IN AND FADE OUT in C#?
using UnityEngine;
using System.Collections;
public class FADE : MonoBehaviour {
private var alpha = 1.0;
private var fadeDir = -1;
private Texture2D myGUITexture;
float fadeSpeed = 0.2;
int drawDepth = -1000;
void OnGUI(){
alpha += fadeDir * fadeSpeed * Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color.a = alpha;
GUI.depth = drawDepth;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeTexture);
}
}
Comment
Answer by say_forever · Nov 18, 2015 at 10:04 AM
Here you go.
using UnityEngine;
public class FADE : MonoBehaviour
{
private float alpha = 1.0f;
private float fadeDir = -1;
public Texture2D myGUITexture;
float fadeSpeed = 0.2f;
int drawDepth = -1000;
void OnGUI()
{
alpha += fadeDir * fadeSpeed * Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha);
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), myGUITexture);
GUI.depth = drawDepth;
}
}