- Home /
Question by
wshiahb · Jan 27, 2018 at 09:56 AM ·
uicamera-movementtouch controlsinterface
How to avoid TouchPhase.Ended effect?
I wrote a touch control script to control the camera for some basic 3d movements, like orbit around, zoom in & out and pan. Also, I want to reset my camera to default position. However, it seems that the TouchPhase.Ended always moves the camera after I press the reset button. Anyone can help to solve this problem.
private void Update()
{
Touch touch = new Touch();
// Orbiting
if (touch.phase != TouchPhase.Ended && Input.touchCount == 1 && !EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
Touch touchZero = Input.GetTouch(0);
_LocalRotation.x += touchZero.deltaPosition.x * 0.5f;
_LocalRotation.y -= touchZero.deltaPosition.y * 0.5f;
_LocalRotation.y = Mathf.Clamp(_LocalRotation.y, -90f, 90f);
isOrbitting = true;
}
}
private void LateUpdate()
{
// Orbiting
if (isOrbitting)
{
Quaternion QT = Quaternion.Euler(_LocalRotation.y, _LocalRotation.x, 0);
this._XForm_Parent.localRotation = Quaternion.Lerp(this._XForm_Parent.rotation, QT, Time.deltaTime * OrbitSpeed);
}
}
public void ResetCamera()
{
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
_XForm_Parent.transform.localPosition = Vector3.zero;
_XForm_Parent.transform.localRotation = Quaternion.identity;
_XForm_Camera.transform.localPosition = new Vector3(0f, 0f, -10f);
Debug.Log("Camera Reset");
}
}
Comment