#pragma strict

//Fade to black
     
var fadeTexture : Texture2D;
var fadeSpeed = 0.1;
var drawDepth = -1000;
     
private var alpha = 0.0;
private var fadeDir = -1;
    
var OnOff = "off";
    
function OnTriggerEnter2D (col : Collider2D)
{
	if(col.gameObject.tag == "Player1" || col.gameObject.tag == "Player2")
	{
		OnOff = "on";
	}
}
     
function OnGUI()
{
  	if (OnOff == "on")
    {
		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);
	}
}