- Home /
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;
           }
       }
   }
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
Your answer
 
 
             Follow this Question
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
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                