yao2yaoblog

如上图的效果,实现起来非常简单。

在场景里找到主摄像头,查看摄像头的Inspector

里面的Field of View属性,尝试拖动改变它的值,看到的就是缩放的效果。

所以只需要写一个脚本控制这个值的大小就行。新建一个脚本叫CameraControl

using UnityEngine;
using System.Collections;

public class CameraControl : MonoBehaviour {

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        //Zoom out
        if (Input.GetAxis("Mouse ScrollWheel") < 0)
        {
            if(Camera.main.fieldOfView <= 100)
                Camera.main.fieldOfView += 2;
        }
        //Zoom in
        if (Input.GetAxis("Mouse ScrollWheel") > 0)
        {
            if(Camera.main.fieldOfView > 40)
                Camera.main.fieldOfView -= 2;
        }
    }
}

运行场景,就得到滚轮缩放场景的效果了。

分类:

技术点:

相关文章:

  • 2018-07-03
  • 2021-05-13
  • 2022-01-11
  • 2021-05-20
  • 2021-06-15
  • 2022-12-23
  • 2021-05-20
猜你喜欢
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案