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 JaMaJ_PL · Jul 29, 2016 at 06:58 PM · c#camerascripting problemobjectbeginner

Changing TPP view to a FPP view after picking up object

I have found a script that allows to change the camera view (e.g. after pressing "f"). I would like to modify it so the camera changes only once in the entire game - in the instance of picking up only one pickable object in a whole game.

The idea is to start the game with TPP, then after picking up object, the camera changes to FPP and stays that way.

It probably is as simple as adding a line for changing the view when the item is destroyed (picked up) but I am a total beginner and I want to ask you for your help. Many thanks.

Here is a code I wish to modify:

 using UnityEngine;
   using System.Collections;
   
   public class VDCameraToggler : MonoBehaviour
   {
       [SerializeField]
       Camera[] CameraArray;
   
       [SerializeField]
       int CurrentCamera = 0;
   
       [SerializeField]
       float KeyDelay = 0.4f;
       [SerializeField]
       float LastKeyInput = 0.0f;
   
       // Use this for initialization
       void Start()
       {
           if (CameraArray.Length < 1)
           {
               Debug.Log("CameraToggler only has one camera and is not needed. The toggler has been disabled.");
               this.gameObject.active = false;
   
               // Ensure if there is 1 camera attached that it is enabled
               if (CameraArray.Length == 1)
                   CameraArray[0].gameObject.active = true;
           }
           else
           {
               // Disable all cameras except for the startup camera
               for (int i = 0; i < CameraArray.Length; i++)
               {
                   if (CurrentCamera == i)
                       CameraArray[i].gameObject.active = true;
                   else
                       CameraArray[i].gameObject.active = false;
               }
           }
       }
   
       // Update is called once per frame
       void Update()
       {
           // Check for user input only if the last input was more than x seconds ago
           // (0.4 seconds is generally enough time to ensure the key capture doesn't happen more than once
           // on a single key press
   
           //if (Input.GetKey(KeyCode.F) && LastKeyInput + KeyDelay <= Time.realtimeSinceStartup) // Can be used instead of the below
           if (Input.GetButton("Switch Camera") && LastKeyInput + KeyDelay <= Time.realtimeSinceStartup) // Can be used instead of the above
           {
               if (CurrentCamera + 1 < CameraArray.Length)
               {
                   // Disable current camera and enable next camera
                   CameraArray[CurrentCamera].gameObject.active = false;
                   CurrentCamera++;
                   CameraArray[CurrentCamera].gameObject.active = true;
               }
               else
               {
                   // Disable current camera and enable first camera
                   CameraArray[CurrentCamera].gameObject.active = false;
                   CurrentCamera = 0;
                   CameraArray[CurrentCamera].gameObject.active = true;
               }
   
               LastKeyInput = Time.realtimeSinceStartup;
           }
       }
   }
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 CausticLasagne · Aug 16, 2016 at 10:07 PM

You'll want to take a look at this if statement. It seems to handle the switching of cameras.

            if (Input.GetButton("Switch Camera") && LastKeyInput + KeyDelay <= Time.realtimeSinceStartup) // Can be used instead of the above
            {

CausticLasagne

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I'm clueless about how to make my script change its position based on how close it is to the wall.. 0 Answers

Rotatearaound a moving object 1 Answer

Respawn Method not reusable between scenes ? 0 Answers

"Follow Target" script with a prefab (C#) Help me please! 1 Answer

How can i track/update the lastPosition of a camera when switching between cameras ? 0 Answers


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