Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 06:09 PM · c#unity 5camerabeginnercycle

How to end a cinematic camera cycle

Hi, I'm new in Unity and I'm learning on my own how to use it

For starters I'm trying to combine different scripts from tutorials into a new project so I can see better what how code works in different contexts

Right now I'm trying to start a 1° person test game with a cynematic sequence. I've worked out how to switch to the player camera (I've resorted to just deactivate the cinematic cameras) but the cycle keeps going. I know I should use break but I don't know how to change the code now

public static bool gameStarted = false;

 [SerializeField]
 private List<GameObject> cinematicCameras;
 [SerializeField]
 private Image screenFader;

 private int activeCamera = 0;
 private int nextCamera;

 private float timer;

 [SerializeField]
 private float timerDelay = 8f;
 [SerializeField]
 private float fadeSpeed = 8f;

 // Use this for initialization
 void Start () {

     cinematicCameras [activeCamera].SetActive (true);
     nextCamera = activeCamera;

 }

 // Update is called once per frame
 void Update() {

     // If the start game key has been pressed...
     if (gameStarted == false && Input.GetKeyUp(KeyCode.Space)) {

         // ...deactivate cinematic cameras
         cinematicCameras[activeCamera].SetActive(false);

     } else {

         // otherwise, cycle through the 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
             cinematicCameras[activeCamera].SetActive (false);
             activeCamera = cameraIndex;
             cinematicCameras[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 > cinematicCameras.Count) {

             // ...then reset to the first cinematic camera.
             nextCamera = 0;

         }
     }

     // Switch to the next camera.
     SwitchCamera(nextCamera);

     }

Some advice would be appreciated, tnx

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Vashar23 · Dec 07, 2016 at 02:29 PM

I've solved it actually.

Changed back to the original script were the player camera was in the camera list but selected only after the start of the game. My problem was that the GameManager script had public bool gameStarted = false and the cameraManager couldn't access it, so I've changed it to public static bool and now it works

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

[Newbie] Particle System not playing, C# (unity 5.5) 3 Answers

How to move the other object without moving the first object? 1 Answer

PS3 third person camera orbit script C# 0 Answers

Can't do Quaternion.AngleAxis twice. 1 Answer

Pinch Zoom and Pan while not calling other functions 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