Search Unity

Input question

Discussion in 'Scripting' started by markus843, Jan 4, 2014.

  1. markus843

    markus843

    Joined:
    Jan 4, 2014
    Posts:
    3
    I'm trying to basically have a camera view for first person, third person, and aiming in on a scope. First person is right alt, third person is left alt, and aiming in is right click(Fire2). When I play it, the third person and first person inputs don't work.
    If I take out the code where it aims in on the scope, it works though
    Here is the code without the aiming in part
    Code (csharp):
    1.         if (Input.GetButton("third person"))
    2.         {
    3.             if (toggleCamera)
    4.             {
    5.                 toggleCamera.camera.enabled = true;
    6.                 mainCamera.camera.enabled = false;
    7.             }
    8.         }
    9.  
    10.  
    11.         if (Input.GetButton("first person"))
    12.         {
    13.             if (toggleCamera)
    14.             {
    15.                 toggleCamera.camera.enabled = false;
    16.                 mainCamera.camera.enabled = true;
    17.             }
    18.         }
    and if I add this, the third person and first person toggle don't work
    Code (csharp):
    1.         if (Input.GetButton("Fire2"))
    2.         {
    3.             if (AimCamera)
    4.             {
    5.                 AimCamera.camera.enabled = true;
    6.                 mainCamera.camera.enabled = false;
    7.             }
    8.         }
    9.         else
    10.         {
    11.  
    12.  
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Check your bracket grouping
     
  3. jgodfrey

    jgodfrey

    Joined:
    Nov 14, 2009
    Posts:
    564
    What's inside the "else" block at the bottom of the posted code? That's going to be executed any time the input is *NOT* "Fire2". So, when the "third person" or "first person" code is accessed at the top, the "else" code will also be accessed - which I'd guess is your problem.

    Jeff
     
  4. markus843

    markus843

    Joined:
    Jan 4, 2014
    Posts:
    3
    I was writing something while writing this thread. Pretend it's not there :p
     
  5. markus843

    markus843

    Joined:
    Jan 4, 2014
    Posts:
    3
    I got it to work, I just added another input and it's good now