• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Vashar23 · Dec 05, 2016 at 07:32 AM · c#unity 5cameracamerascamera.main

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to detect an object which be in FOV of certain camera ? 1 Answer

How can I switch between two cameras ? 1 Answer

How to switch back a camera after an interval using a Trigger 0 Answers

how to switch cameras C# 0 Answers

How to end a cinematic camera cycle 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges