unity 摄像头拉进代码

unity 摄像机拉伸

拼接完成后的摄像机拉进拉远代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class camera : MonoBehaviour
{
    // Start is called before the first frame update
   // private float MovingSpeed = 3f;         //移动屏幕的速度
    float delta_x, delta_y, delta_z;            //计算移动量
    float distance = 5;
    float ZoomSpeed = 5f;                  //拉近拉远速度

    void Start()
    {
        
    }
    public bool isFar = true;
    // Update is called once per frame
    void Update()
    {

        if (Input.GetAxis("Mouse ScrollWheel") != 0)
        {//滚轴拉近拉远
            delta_z = -Input.GetAxis("Mouse ScrollWheel") * ZoomSpeed;
            transform.Translate(0, 0, -delta_z);
            distance += delta_z;
        }

        if (Input.GetMouseButtonDown(1))
        {
            //isFar = !isFar;
            //if(isFar)
            //{
                //if (GetComponent().fieldOfView < 60)
                    GetComponent<Camera>().fieldOfView += 2;
            //}
            //else
            //{
               // if (GetComponent().fieldOfView > 20)
            //}
        }
        else if(Input.GetMouseButtonDown(0))
        {
            GetComponent<Camera>().fieldOfView -= 2;
            //GetComponent(). -= 2;
        }
    }
}

你可能感兴趣的:(unity,c#,unity,游戏引擎)