Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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,831
    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,831
    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 :)