Search Unity

  1. Unity 2019.1 is now released.
    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:
    2,472
    Is your camera ortho or perspective?
     
  3. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    324
    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:
    2,472
    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 :)