标签:backValue obj 查看 Space Vector3 private 旋转 UNITY else
PC端:
using UnityEngine; using System.Collections; public class DragRound : MonoBehaviour { public Transform obj; public float speed = 2; private bool _mouseDown = false; void Update () { if (Input.GetMouseButtonDown(0)) _mouseDown = true; else if (Input.GetMouseButtonUp(0)) _mouseDown = false; if (_mouseDown) { float fMouseX = Input.GetAxis("Mouse X"); float fMouseY = Input.GetAxis("Mouse Y"); obj.Rotate(Vector3.up, -fMouseX * speed, Space.World); obj.Rotate(Vector3.right, fMouseY * speed, Space.World); } } }
手机端:
using UnityEngine; using System.Collections; public class DragRoundPhone : MonoBehaviour { private Vector3 startFingerPos; private Vector3 nowFingerPos; private float xMoveDistance; private float yMoveDistance; private int backValue = 0; public GameObject obj; void Update() { if (Input.touchCount <= 0) { return; } if (Input.GetTouch(0).phase == TouchPhase.Began) { //Debug.Log("======开始触摸====="); startFingerPos = Input.GetTouch(0).position; } nowFingerPos = Input.GetTouch(0).position; if ((Input.GetTouch(0).phase == TouchPhase.Stationary) || (Input.GetTouch(0).phase == TouchPhase.Ended)) { startFingerPos = nowFingerPos; //Debug.Log("======释放触摸====="); return; } // if (Input.GetTouch(0).phase == TouchPhase.Ended) { // // } if (startFingerPos == nowFingerPos) { return; } xMoveDistance = Mathf.Abs(nowFingerPos.x - startFingerPos.x); yMoveDistance = Mathf.Abs(nowFingerPos.y - startFingerPos.y); if (xMoveDistance > yMoveDistance) { if (nowFingerPos.x - startFingerPos.x > 0) { //Debug.Log("=======沿着X轴负方向移动====="); backValue = -1; //沿着X轴负方向移动 } else { //Debug.Log("=======沿着X轴正方向移动====="); backValue = 1; //沿着X轴正方向移动 } } else { if (nowFingerPos.y - startFingerPos.y > 0) { //Debug.Log("=======沿着Y轴正方向移动====="); backValue = 2; //沿着Y轴正方向移动 } else { //Debug.Log("=======沿着Y轴负方向移动====="); backValue = -2; //沿着Y轴负方向移动 } } if (backValue == -1) { obj.transform.Rotate(Vector3.up * -1 * Time.deltaTime * 50, Space.World); } else if (backValue == 1) { obj.transform.Rotate(Vector3.up * Time.deltaTime * 50, Space.World); } else if (backValue == 2) { obj.transform.Rotate(Vector3.right * Time.deltaTime * 50, Space.World); } else if (backValue == -2) { obj.transform.Rotate(Vector3.right * -1 * Time.deltaTime * 50, Space.World); } } }
标签:backValue,obj,查看,Space,Vector3,private,旋转,UNITY,else 来源: https://www.cnblogs.com/guangzhiruijie/p/15829560.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。