Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

How to zoom in or out?

Discussion in 'Cinemachine' started by SullenShark, Oct 2, 2018.

  1. SullenShark

    SullenShark

    Joined:
    Mar 17, 2018
    Posts:
    7
    Hello,

    This is my first time using Cinemachine and I am figuring out how to zoom in or out on my character using the 2D Camera with my mouse wheel.

    How do I do this in C#?


    Thank You Very Much. :)
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    Is your camera ortho or perspective?
     
  3. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    and do you really mean zoom or do you want to dolly the camera closer and further away?
     
  4. SullenShark

    SullenShark

    Joined:
    Mar 17, 2018
    Posts:
    7
    Ortho and Dolly
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    If you're ortho then dolly won't change anything (because there's no perspective). You'll have to modify OrthographicSize if you want to see a difference onscreen. Just add a script to modify vcam.m_Lens.OrthographicSize according to mouse wheel.
     
  6. SullenShark

    SullenShark

    Joined:
    Mar 17, 2018
    Posts:
    7
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class Zoom : MonoBehaviour {
    5.  
    6.     void Update()
    7.     {
    8.  
    9.         if (Input.GetAxis("Mouse ScrollWheel") > 0)
    10.         {
    11.           //GetComponent<CinemachineVirtualCamera>().m_Lens.OrthographicSize = ++;
    12.             GetComponent<CinemachineVirtualCamera>().m_Lens.OrthographicSize = 5;
    13.         }
    14.         if (Input.GetAxis("Mouse ScrollWheel") < 0)
    15.         {
    16.           //GetComponent<CinemachineVirtualCamera>().m_Lens.OrthographicSize = --;
    17.             GetComponent<CinemachineVirtualCamera>().m_Lens.OrthographicSize = 20;
    18.         }
    19.     }
    20. }
    Thank you so much for the REPLY :)