Hi, all: our APP made with unity(5.6.0), we need to scale the model by two fingers. And also we need to take a picture by calling image picker. However, once we did took a photo then we can't scale the model cuz APP can only detected first touch. The state of multipletouchenabled is true. Here is the flow: we scale the model by two fingers ------- works fine. take photo ---- get the texture data; we scale the model by two fingers ----- Only can detect first touch, seems like multipletouchenable is false, but the log show multipletoucheable is true!!! pls help
Code (CSharp): public class ScaleController : MonoBehaviour { public float MinScale = 0.1f; public float MaxScale = 0.5f; private InstantTrackerController _controller; private Transform _activeObject = null; private Vector3 _touch1StartGroundPosition; private Vector3 _touch2StartGroundPosition; private Vector3 _startObjectScale; private void Start () { _controller = GetComponent<InstantTrackerController>(); } private void Update () { if (Input.touchCount >= 2) { Touch touch1 = Input.GetTouch(0); Touch touch2 = Input.GetTouch(1); Transform hitTransform; if (_activeObject == null) { if (GetTouchObject(touch1.position, out hitTransform)) { SetTouchObject(hitTransform); } else if (GetTouchObject(touch2.position, out hitTransform)) { SetTouchObject(hitTransform); } else if (GetTouchObject((touch1.position + touch2.position) / 2, out hitTransform)) { SetTouchObject(hitTransform); } if (_activeObject != null) { _touch1StartGroundPosition = GetGroundPosition(touch1.position); _touch2StartGroundPosition = GetGroundPosition(touch2.position); _startObjectScale = _activeObject.localScale; } } if (_activeObject != null) { var touch1GroundPosition = GetGroundPosition(touch1.position); var touch2GroundPosition = GetGroundPosition(touch2.position); float startMagnitude = (_touch1StartGroundPosition - _touch2StartGroundPosition).magnitude; float currentMagnitude = (touch1GroundPosition - touch2GroundPosition).magnitude; _activeObject.localScale = _startObjectScale * (currentMagnitude / startMagnitude); if (_activeObject.localScale.x < MinScale) { _activeObject.localScale = new Vector3(MinScale, MinScale, MinScale) ; } if (_activeObject.localScale.x > MaxScale) { _activeObject.localScale = new Vector3(MaxScale, MaxScale, MaxScale); } } } else { _activeObject = null; } } private bool GetTouchObject(Vector2 touchPosition, out Transform hitTransform) { var touchRay = Camera.main.ScreenPointToRay(touchPosition); touchRay.origin -= touchRay.direction * 100.0f; RaycastHit hit; if (Physics.Raycast(touchRay, out hit, 400.0f, LayerMask.GetMask("Sofa"))) { hitTransform = hit.transform.root; return true; } hitTransform = null; return false; } private Vector3 GetGroundPosition(Vector2 touchPosition) { var groundPlane = new Plane(Vector3.up, Vector3.zero); var touchRay = Camera.main.ScreenPointToRay(touchPosition); float enter; if (groundPlane.Raycast(touchRay, out enter)) { return touchRay.GetPoint(enter); } return Vector3.zero; } private void SetTouchObject(Transform newObject) { Debug.Log("ScaleController.SetTouchObject 1"); // foreach (var obj in _controller.ActiveModels.Values) foreach (SofaItem item in _controller.ActiveModels) { Debug.Log("ScaleController.SetTouchObject 2"); if (item.obj == newObject.gameObject) { Debug.Log("ScaleController.SetTouchObject 3"); _activeObject = newObject; Debug.Log(_activeObject.name); } } } }
Please use code tags https://forum.unity3d.com/threads/using-code-tags-properly.143875/ It's almost impossible to read without them (you may need to paste it again to ensure formatting is not lost).