unity鼠标左键拖拽旋转模型滚轮放大缩小模型

来源:互联网 发布:漫威奇异博士 实力知乎 编辑:程序博客网 时间:2024/05/16 00:51
using UnityEngine;public class DragTest : MonoBehaviour{    Vector3 scale;    float offset=0.2f;    float maxSize=2.0f;    float minSize = 0.4f;    public float speed = 200f;// Use this for initialization    void Start()    {        scale = this.transform.localScale;    }    // Update is called once per frame    void Update()    {        //鼠标滚轮的效果        //Zoom out        if (Input.GetAxis("Mouse ScrollWheel") < 0)        {            if (scale.x <= maxSize)            {                scale.x += offset;                scale.y += offset;                scale.z += offset;                this.transform.localScale = scale;            }        }        //Zoom in        if (Input.GetAxis("Mouse ScrollWheel") > 0)        {            if (scale.x > minSize)            {                scale.x -= offset;                scale.y -= offset;                scale.z -= offset;                this.transform.localScale = scale;            }        }        //鼠标左键旋转物体        if (Input.GetMouseButton(0))        {            float axis = Input.GetAxis("Mouse X");            this.transform.Rotate(Vector3.up * Time.deltaTime * speed * axis);        }    }}

阅读全文
0 0