Game Development Reference
In-Depth Information
Now, the scene should have three cameras: two separate and disabled cameras at
different locations (cameras X and Y ), and one main camera at the scene's origin
(camera Z ). On this basis, the following code sample 5-9 can be assigned to camera Z ,
and this allows fading between cameras X and Y when Space bar is pressed:
001 //Class to fade from camera 0 to 1, and back from 1 to 0
002 //This class assumes there are only two scene cameras
003 //---------------------------------------
004 using UnityEngine;
005 using System.Collections;
006 //---------------------------------------
007 public class CameraFader : MonoBehaviour
008 {
009 //---------------------------------------
010 //All cameras in the scene to be composited
011 public Camera[] Cameras;
012
013 //Color to multiply with render)
014 public Color[] CamCols = null;
015
016 //Fade in/out time in seconds
017 public float FadeTime = 2.0f;
018
019 //Material used as shader to final render
020 public Material Mat = null;
021 //---------------------------------------
022 // Use this for initialization
023 void Start ()
024 {
025 //Assign render textures to each camera
026 foreach(Camera C in Cameras)
027 C.targetTexture = new
RenderTexture(Screen.width, Screen.height,
24); //Create texture
028 }
029 //---------------------------------------
030 //Called once per frame after the camera has
031 //finished rendering but before the render is shown
032 //Companion function: OnPreRender
033 void OnPostRender()
034 {
035 //Define screen rect
036 Rect ScreenRct = new
Rect(0,0,Screen.width,Screen.height);
 
Search WWH ::




Custom Search