void Update() {
if (Input.touchCount == 0) {
return;
}
if (Input.touches[0].phase == TouchPhase.Began) {
m_screenpos = Input.touches[0].position;
}
if (Input.touches[0].phase == TouchPhase.Ended && Input.touches[0].phase != TouchPhase.Canceled) {
Vector2 pos = Input.touches[0].position;
if (Mathf.Abs (m_screenpos.x - pos.x) > Mathf.Abs (m_screenpos.y - pos.y)) {
if (m_screenpos.x > pos.x) {
m_transform.Translate (- Vector3.right * m_moveSpeed * Time.deltaTime);
}
else {
m_transform.Translate (Vector3.right * m_moveSpeed * Time.deltaTime);
}
}
else {
if (m_screenpos.y > pos.y) {
m_transform.Translate (-Vector3.up * m_updownSpeed * Time.deltaTime);
}
else {
m_transform.Translate (Vector3.up * m_updownSpeed * Time.deltaTime);
}
}
}
}
基础代码--物体向手指滑向的方向移动
最新推荐文章于 2020-03-26 17:05:35 发布