十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
using UnityEngine; using System.Collections; public class mouseRotateAndScale : MonoBehaviour { GameObject car; //public GameObject light; Vector2 p1, p2;//用来记录鼠标的位置,以便计算旋转幅度 // 鼠标中间键 int MouseWheelSensitivity = 5; int MouseZoomMin = 18; int MouseZoomMax = 90; float normalDistance = 60; // Use this for initialization void Start () { car = GameObject.Find("benchi"); } // Update is called once per frame void Update () { //旋转 if (Input.GetMouseButtonDown(0)) { p1 = new Vector2(Input.mousePosition.x, Input.mousePosition.y);//鼠标左键按下时记录鼠标位置p1 } if (Input.GetMouseButton(0)) { p2 = new Vector2(Input.mousePosition.x, Input.mousePosition.y);//鼠标左键拖动时记录鼠标位置p2 if (transform.position.y >= 20 && transform.position.y <= 130) //控制在20-130之内 { float dx = p2.x - p1.x; float dy = (float)0.6 * (p2.y - p1.y); //鼠标上下移动 transform.Translate(-dy * Vector3.up * Time.deltaTime); transform.RotateAround(car.transform.position, Vector3.up, dx * Time.deltaTime); } else if (transform.position.y < 20 && p2.y < p1.y) { float dx = p2.x - p1.x; float dy = (float)0.6 * (p2.y - p1.y); //鼠标上下移动 transform.Translate(-dy * Vector3.up * Time.deltaTime); transform.RotateAround(car.transform.position, Vector3.up, dx * Time.deltaTime); } else if (transform.position.y > 130 && p2.y > p1.y) { float dx = p2.x - p1.x; float dy = (float)0.6 * (p2.y - p1.y); //鼠标上下移动 transform.Translate(-dy * Vector3.up * Time.deltaTime); transform.RotateAround(car.transform.position, Vector3.up, dx * Time.deltaTime); } //下面开始旋转,仅在水平方向上进行旋转 //else if (transform.position.y < 20) //{ // transform.position.y = 20.1f; //} //else if (transform.position.y > 130) //{ // transform.position.y = 129.9f; //} //light.transform.RotateAround(car.transform.position, Vector3.up, dx * Time.deltaTime); } //鼠标滚轮控制场景大小 // 如果按住滑轮 if (Input.GetAxis("Mouse ScrollWheel") > 0) { Debug.Log(1); Debug.Log(Input.GetAxis("Mouse ScrollWheel")); if (normalDistance >= MouseZoomMin && normalDistance <= MouseZoomMax) { normalDistance -= Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity; } if (normalDistance < MouseZoomMin) { normalDistance = MouseZoomMin; } if (normalDistance > MouseZoomMax) { normalDistance = MouseZoomMax; } // transform.Translate(transform.forward * normalDistance); transform.camera.fieldOfView = normalDistance; } //后滚 else if (Input.GetAxis("Mouse ScrollWheel") < 0) { Debug.Log(-1); if (normalDistance >= MouseZoomMin && normalDistance <= MouseZoomMax) { normalDistance -= Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity; } if (normalDistance < MouseZoomMin) { normalDistance = MouseZoomMin; } if (normalDistance > MouseZoomMax) { normalDistance = MouseZoomMax; } // transform.Translate(-transform.forward * normalDistance); transform.camera.fieldOfView = normalDistance; } } }
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
创新互联是一家集网站建设,东阿企业网站建设,东阿品牌网站建设,网站定制,东阿网站建设报价,网络营销,网络优化,东阿网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。