Search Unity

Camera Switch + Increase Fog Temporarily

Discussion in 'Scripting' started by lapfire, Apr 8, 2014.

  1. lapfire

    lapfire

    Joined:
    Mar 9, 2011
    Posts:
    62
    Hello Unity community, I'm pretty new to be honest and I have a question. I have a script that I want to fade between two cameras at a constant interval (5 seconds). When the camera switches, I want the screen to fade to black for about a second before fading in to see the new camera angle.

    The best way I can think of doing this (since I have Unity Basic) is to increase the fog density to 1, and then back to 0. However, that would make the screen go instantly black rather than fade to black. I'm lost in the code, and have no idea where to go. Any direction would be very much appreciated. The code I am using is below.

    Code (csharp):
    1.  
    2. var cam1 : Camera;
    3. var cam2 : Camera;
    4.  
    5. function Start() {
    6.     cam1.enabled = true;
    7.     cam2.enabled = false;
    8.     RenderSettings.fog = true;
    9. }
    10.  
    11. var myTimer : float = 5.0;
    12. var myWaitTime : float = 2.0;
    13.  
    14. function Update () {
    15.  if(myTimer > 0){
    16.   myTimer -= Time.deltaTime;
    17.  }
    18.  
    19.  if(myTimer <= 0){
    20.   myTimer = 5.0;
    21.   RenderSettings.fogDensity = 1.0;
    22.   cam1.enabled = !cam1.enabled;
    23.  
    24.   function UpdateWait () {
    25.   if(myWaitTime > 0){
    26.   myWaitTime -= Time.deltaTime;
    27.   }
    28.  
    29.   if(myWaitTime <=0{
    30.   myWaitTime = 2.0;
    31.   cam2.enabled = !cam2.enabled;
    32.   }
    33.  
    34.   RenderSettings.fogDensity = 0.0;
    35.  }
    36. }
    37.  
     
  2. lapfire

    lapfire

    Joined:
    Mar 9, 2011
    Posts:
    62
    Code (csharp):
    1.  
    2. var cam1 : Camera;
    3. var cam2 : Camera;
    4.  
    5. function Start() {
    6.     cam1.enabled = true;
    7.     cam2.enabled = false;
    8.     RenderSettings.fog = true;
    9. }
    10.  
    11. var myTimer : float = 5.0;
    12.  
    13. function Update () {
    14.  if(myTimer > 0){
    15.   myTimer -= Time.deltaTime;
    16.  }
    17.  
    18.  if(myTimer <= 0){
    19.   myTimer = 5.0;
    20.   RenderSettings.fogDensity = 1.0;
    21.   cam1.enabled = !cam1.enabled;
    22.   cam2.enabled = !cam2.enabled;
    23.   RenderSettings.fogDensity = 0.0;
    24.  }
    25. }
    26.  
    If it helps anyone, this is the last time that the code I am using actually works. It switches between two cameras after 5 seconds, but does not achieve the "fade to black" aspect I am looking for.

    Thank you all very much.