[Unity3D] Unity3D game development-scroll wheel to zoom in and out

Source: Internet
Author: User

Hello, everyone. Welcome to the Unity3D Game Development Series articles that I bring to you. My blog address is http://blog.csdn.net/qinyuanpei.

Today, we will share with you the following:


Next we will write a script code:

using UnityEngine;using System.Collections;public class CameraZoom : MonoBehaviour {void Start () {}void Update () {//Zoom outif (Input.GetAxis("Mouse ScrollWheel") <0)        {           if(Camera.main.fieldOfView<=100)           Camera.main.fieldOfView +=2;           if(Camera.main.orthographicSize<=20)           Camera.main.orthographicSize +=0.5F;        }//Zoom in    if (Input.GetAxis("Mouse ScrollWheel") > 0)    {      if(Camera.main.fieldOfView>2)Camera.main.fieldOfView-=2;  if(Camera.main.orthographicSize>=1)    Camera.main.orthographicSize-=0.5F;    }}}
From the code above, we can see that we can zoom in and out the scene by changing the camera's field of view, and we use the GetAxis () method for mouse wheel monitoring, the following shows the demo Animation:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.