1 void Update() 2 { 3 //左Ctrl鍵 4 if (Input.GetKey(KeyCode.LeftControl)) 5 { 6 B_LeftCtrl = true; 7 } 8 else 9 { 10 B_LeftCtrl = false; 11 } 12 13 if (Input.GetMouseButton(0) && B_LeftCtrl)//鼠標左鍵+左Ctrl 14 { 15 float mouseX = Input.GetAxis("Mouse X");//獲取鼠標X軸滑動參數 16 float mouseY = Input.GetAxis("Mouse Y");//獲取鼠標Y軸滑動參數 17 //鼠標XY軸滑動控制物體旋轉 18 GameObject.Find("地形").transform.Rotate(new Vector3(mouseY * Time.deltaTime * rotateSpeed, -mouseX * Time.deltaTime * rotateSpeed)); 19 } 20 21 if (Input.GetMouseButton(1) && B_LeftCtrl)//鼠標右鍵+左Ctrl 22 { 23 float mouseX = Input.GetAxis("Mouse X");//獲取鼠標X軸滑動參數 24 float mouseY = Input.GetAxis("Mouse Y");//獲取鼠標Y軸滑動參數 25 26 GameObject.Find("地形").transform.Translate(new Vector3(mouseX * Time.deltaTime * moveSpeed,mouseY * Time.deltaTime * moveSpeed,0)); 27 } 28 29 if (B_LeftCtrl)//左Ctrl鍵 30 { 31 //W、A、S、D 控制移動 32 float horizontal = Input.GetAxis("Horizontal"); //獲取橫軸參數。 33 float vertical = Input.GetAxis("Vertical"); //獲取垂直參數。 34 35 GameObject.Find("地形").transform.Translate(new Vector3(horizontal * Time.deltaTime * moveSpeed, 0, vertical * Time.deltaTime * moveSpeed)); 36 37 //鼠標中鍵控制物體滾軸縮放 38 float mouseScrollWheel = Input.GetAxis("Mouse ScrollWheel"); 39 GameObject.Find("地形").transform.localScale += new Vector3(mouseScrollWheel, mouseScrollWheel, mouseScrollWheel); 40 } 41 }
