中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

[unity3d]鼠標拖動and旋轉縮放

發布時間:2020-02-26 12:03:43 來源:網絡 閱讀:430 作者:蓬萊仙羽 欄目:游戲開發
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;         } 	} } 

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

缙云县| 临海市| 县级市| 墨竹工卡县| 密云县| 读书| 华容县| 靖江市| 锡林浩特市| 峨山| 浮梁县| 黄浦区| 祁连县| 朔州市| 遵义县| 嘉峪关市| 承德市| 宁安市| 昌乐县| 佛坪县| 贵港市| 五华县| 内乡县| 五指山市| 屯昌县| 天峨县| 沭阳县| 沁水县| 阿坝| 乐业县| 淅川县| 平顺县| 达孜县| 绍兴县| 泾川县| 交口县| 万山特区| 乐平市| 德令哈市| 神农架林区| 车致|