- Home /
Camera Zoom not working
I'm making a top-down rpg and have an orthographic camera. I made a script that controls different variables on the camera (mainly changing the target). When I was adding the zoom feature it didn't work properly:
  public GameObject NewTarget;
     public CameraController Camera;
     public Camera MainCam;
     public GameObject Player;
     public float CameraZoom;
     public float CameraZoomDefault;
 
     // Use this for initialization
     void Start()
     {
         CameraZoomDefault = MainCam.orthographicSize;        
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.gameObject.name == "Player")
         {
             Camera.Target = NewTarget;
             MainCam.orthographicSize = CameraZoom;
         }
 
     }
 
     void OnTriggerExit2D(Collider2D other)
     {
         if (other.gameObject.name == "Player")
         {
             Camera.Target = Player;
             CameraZoom = CameraZoomDefault;
             
         }
 
     }
Everything except the zoom is working. I can make the camera zoom out when I enter the trigger but when I exit it doesn't zoom back in. Thanks in advance!
Answer by JFGames · Mar 12, 2017 at 05:25 PM
I fixed the problem, but I'm still not quite sure what caused it. I eventually changed the way the triggers activate everything and it ended up working.
Your answer
 
 
             Follow this Question
Related Questions
Switching Cameras - Confusion with Two Code Samples 2 Answers
How do you zoom with an orthographic camera? 1 Answer
Aquarium like camera 1 Answer
Moving (teleporting) player and camera when they enter a certain area 5 Answers
How to make WorldToScreenPoint work with an orthographic camera? 0 Answers
