- Home /
 
Switching from a cinematic cycle to the player camera
Hi, I'm new in Unity and I'm trying to learn the coding on my own
I'm going for a simple exercise were I combine different codes from other tutorial into a new project so I can see how to script into different contexts
I'm trying now to start the game with a cinematic sequence for then switching to a first person controller, but I can't find an example on how to change the script
 public static bool gameStarted = false;
 [SerializeField]
 private List<GameObject> cameras;
 [SerializeField]
 private Image screenFader;
 private int activeCamera = 1;
 private int nextCamera;
 private float timer;
 [SerializeField]
 private float timerDelay = 8f;
 [SerializeField]
 private float fadeSpeed = 8f;
 // Use this for initialization
 void Start () {
     cameras [activeCamera].SetActive (true);
     nextCamera = activeCamera;
 }
 
 // Update is called once per frame
 void Update () {
     // If the game has started...
     if (gameStarted == true) {
         // ...switch to the player camera
         SwitchCamera(0);
     } else {
         // otherwise, cycle through the other cameras.
         CycleCameras();
     }
 
 }
 private void SwitchCamera(int cameraIndex) {
     if (cameraIndex != activeCamera) {
         // If the screen fade is less then (almost) full black...
         if (screenFader.color.a <= 0.998f) {
             // ...then continue lerping the screen fader towards black.
             screenFader.color = Color.Lerp (screenFader.color, Color.black, fadeSpeed * Time.deltaTime);
         } else {
             // ...set the screen fader to black.
             screenFader.color = Color.black;
             // Change the active camera
             cameras [activeCamera].SetActive (false);
             activeCamera = cameraIndex;
             cameras [activeCamera].SetActive (true);
         }
     } else {
         // If the screen fader is not close to completely clear...
         if (screenFader.color.a <= 0.002f) {
             // ...then continue lerping the screen fader towards clear
             screenFader.color = Color.Lerp (screenFader.color, Color.clear, fadeSpeed * Time.deltaTime);
         } else {
             // ..set the screen fader to clear.
             screenFader.color = Color.clear;
         }
     }
 }
 private void CycleCameras() {
     // Increment a timer to count up to restarting
     timer = timer + Time.deltaTime;
     // If the timer reaches the restart delay...
         if (timer >= timerDelay) {
             // Then reset the timer
             timer = 0f;
             // Choose the next camera
             nextCamera++;
             // If the next camera is greater then the highest index in the camera list...
             if (nextCamera > cameras.Count - 1) {
                 // ...then reset to the first cinematic camera.
                 nextCamera = 1;
         }
     }
             // Switch to the next camera.
             SwitchCamera(nextCamera);
 }
 
               Inserting the player camera in the script list seems to work under different conditions but then the cycle doesn't stop when I start the game
A little advice would be appreciated
Your answer
 
             Follow this Question
Related Questions
Rotating player relative to the camera (Unity C#) 1 Answer
Good Game by One Person, Is it Possible? 2 Answers
Change the FOV from "60" to "90" smoothly when pressing "W" (C#, first time posting, beginner) 2 Answers
How to set Body and Aim properties of Cinemachine Virual Camera via script? 1 Answer
Multiple Cars not working 1 Answer