//Class to fade from camera 0 to 1, and back from 1 to 0 //This class assumes there are only two scene cameras //--------------------------------------- using UnityEngine; using System.Collections; //--------------------------------------- public class CameraFader : MonoBehaviour { //--------------------------------------- //Reference to cameras (all cameras in the scene to be composited) public Camera[] Cameras; //Reference to camera color (color to multiply with render) public Color[] CamCols = null; //Fade in/out time in seconds (total time for a fade in one direction) public float FadeTime = 2.0f; //Final material to apply to render (Can be used to apply a shader to final rendered pixels) public Material Mat = null; //--------------------------------------- // Use this for initialization void Start () { //Assign render textures to each camera foreach(Camera C in Cameras) C.targetTexture = new RenderTexture(Screen.width, Screen.height, 24); //Create texture } //--------------------------------------- //This function is called once per frame after the camera has //finished rendering but before the render is shown //It has a companion function OnPreRender (which is called before rendering) void OnPostRender() { //Define screen rect Rect ScreenRct = new Rect(0,0,Screen.width,Screen.height); //Source Rect Rect SourceRect = new Rect(0,1,1,-1); //Render each camera to their target texture for(int i = 0; i