Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to hold a button to change the camera perspective?

Discussion in 'Scripting' started by EliteWalrus, Aug 17, 2014.

  1. EliteWalrus

    EliteWalrus

    Joined:
    Aug 16, 2014
    Posts:
    44
    note: I have the GameObjects setup in the inspector and the camera switches to thirdPerson properly but won't go back.

    Here is what I've tried:

    Code (JavaScript):
    1. var topDown : GameObject;
    2. var thirdPerson : GameObject;
    3.  
    4. function Update ()
    5. {
    6.     if(Input.GetButtonDown("Fire2"))
    7.         {
    8.             topDown.SetActive(false);
    9.             thirdPerson.SetActive(true);
    10.         }
    11.      
    12.     if(Input.GetButtonUp("Fire2"))
    13.         {
    14.         topDown.SetActive(true);
    15.         thirdPerson.SetActive(false);
    16.         }
    17. }
     
    Last edited: Aug 17, 2014
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    That isn't enough code to see what is happening.
     
  3. EliteWalrus

    EliteWalrus

    Joined:
    Aug 16, 2014
    Posts:
    44
    I have made a top down camera and a third person camera. I want to hold "Fire 2" to disable topDown and enable thirdPerson and when I release I want the top down camera to become active again.
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    I understand what you are trying to do, but since you don't show what happens when the various items are active or not, I can't help.
     
  5. EliteWalrus

    EliteWalrus

    Joined:
    Aug 16, 2014
    Posts:
    44
    That's the entirety of the script . Nothing else involved. The topDown Camera gets disabled and thirdPerson camera gets enabled but the problem is, when I release right click topDown does enable and thirdPerson doesn't disable.
     
  6. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Hm.
    I would change the class variable from GameObject to Camera. And use cam.enabled instead of setActive.


    Try that.
     
  7. dvora

    dvora

    Joined:
    Aug 15, 2014
    Posts:
    1
    Try setting the tags of both the cameras to "untagged".