Question by 
               KillitsGaming · Dec 01, 2015 at 10:39 AM · 
                c#camerafieldofview  
              
 
              sniper zoom in but not out C#
Hi the sniper wont zoom back out ather its zoomed in with camera.fieldOfView
public class Sniper : MonoBehaviour {
 public Vector3 HP;
 public Vector3 AP;
 public Camera charCam;
 public Camera sniperCam;
 public AudioListener SniperAud;
 public AudioListener CharAud;
 // Use this for initialization
 void Start()
 {
     transform.localPosition = HP;
     charCam.enabled = true;
     sniperCam.enabled = false;
     CharAud.enabled = true;
     SniperAud.enabled = false;
 }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonUp("Fire2"))
     {
         transform.localPosition = HP;
         charCam.enabled = true;
         sniperCam.enabled = false;
         sniperCam.fieldOfView = 30;
         CharAud.enabled = true;
         SniperAud.enabled = false;
     }
     else
     {
         if (Input.GetButtonDown("Fire2"))
         {
             transform.localPosition = AP;
             charCam.enabled = false;
             sniperCam.enabled = true;
             CharAud.enabled = false;
             SniperAud.enabled = true;
         }
     }
            //Here is the start of zoom
     if (Input.GetKeyDown(KeyCode.Z))
     {
         sniperCam.fieldOfView = 10;
     }
     else
    {    // here is the zoom out that wont work
         if (Input.GetKeyDown(KeyCode.Z) && sniperCam.fieldOfView == 10)
         {
             sniperCam.fieldOfView = 30;
         }
     }
 }
 
               }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by m0guz · Dec 01, 2015 at 11:50 AM
Didn't test the code but this between the 44-54 lines doesn't seem to be right. Especially else-if part.
         //Here is the start of zoom
         if (Input.GetKeyDown(KeyCode.Z))
         {
             sniperCam.fieldOfView = 10;
         }
 
         if (Input.GetKeyDown(KeyCode.Z) && sniperCam.fieldOfView == 10)
         {
             sniperCam.fieldOfView = 30;
         }
 
                   if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Z))
     {
          if (sniperCam.fieldOfView == 10)
         {
             sniperCam.fieldOfView = 30;
          }
         else
          {
              sniperCam.fieldOfView = 10;
         }
    }
 
                 @saschandroid it works now thanks for that i was wanting push the button zoom the button again to zoom out if theirs a way to do that thank you again 
Your answer