// if (Input.touchCount == 1) { // , if (!compressing && !decompressing) { Touch singleTouch = Input.GetTouch(0); Vector3 targetPoint = Camera.main.ScreenToWorldPoint (singleTouch.position); targetPoint = new Vector3 (targetPoint.x, targetPoint.y, 0); transform.position = Vector3.MoveTowards (transform.position, targetPoint, movementSpeed * Time.deltaTime); } }
if (Input.touchCount > 1) { // . Touch touch1 = Input.GetTouch(0); Touch touch2 = Input.GetTouch(1); // , if (!compressing && !decompressing) { Vector3 targetPoint = Camera.main.ScreenToWorldPoint ((touch1.position + touch2.position) / 2); targetPoint = new Vector3 (targetPoint.x, targetPoint.y, 0); transform.position = Vector3.MoveTowards (transform.position, targetPoint, movementSpeed * Time.deltaTime); } float currentDistance = Vector2.Distance(touch1.position, touch2.position); if(pastFingersDistance == 0) { // , pastFingersDistance = currentDistance; }else if(currentDistance < pastFingersDistance - fingersMunchDetectionMin) { // . , . SetCompression(); }else if(currentDistance > pastFingersDistance + fingersMunchDetectionMin) { // . , . SetDecompression(); } } // , . if(Input.touchCount < 2) pastFingersDistance = 0; // , - . if(Input.touchCount < 2 && isCompressed) SetDecompression();
if (Input.touchCount > 1) { // . Touch touch1 = Input.GetTouch(0); Touch touch2 = Input.GetTouch(1); // if (!compressing && !decompressing) { float touch1Time = 0; float touch2Time = 0; // 1 if (tapsHash.Contains (touch1.fingerId)) { float startTouch1Time = (float) tapsHash [touch1.fingerId]; touch1Time = Time.time - startTouch1Time; } // 2 if (tapsHash.Contains (touch2.fingerId)) { float startTouch2Time = (float) tapsHash [touch2.fingerId]; touch2Time = Time.time - startTouch2Time; } // , . if (touch1Time > SECONDS_FOR_TAP && touch2Time > SECONDS_FOR_TAP) { Vector3 targetPoint = Camera.main.ScreenToWorldPoint ((touch1.position + touch2.position) / 2); targetPoint = new Vector3 (targetPoint.x, targetPoint.y, 0); transform.position = Vector3.MoveTowards (transform.position, targetPoint, movementSpeed * Time.deltaTime); } } float currentDistance = Vector2.Distance(touch1.position, touch2.position); if(pastFingersDistance == 0) { // , pastFingersDistance = currentDistance; }else if(currentDistance < pastFingersDistance - fingersMunchDetectionMin) { // . , . SetCompression(); }else if(currentDistance > pastFingersDistance + fingersMunchDetectionMin) { // . , . SetDecompression(); } } // , . if(Input.touchCount < 2) pastFingersDistance = 0; // , - . if(Input.touchCount < 2 && isCompressed) SetDecompression(); // . SetTapAttackListener ();
void SetTapAttackListener() { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { // DetectOneTouchTap (touch); } } } void DetectOneTouchTap(Touch touch) { if (touch.phase == TouchPhase.Began) { // , - . // - , - . tapsHash.Add (touch.fingerId, Time.time); } else if(touch.phase == TouchPhase.Ended) { float startTouchTime = (float) tapsHash [touch.fingerId]; float timeOfTouch = Time.time - startTouchTime; // , if (timeOfTouch <= SECONDS_FOR_TAP) { SetCompression(); SetDecompression(); } tapsHash.Remove (touch.fingerId); } }
Source: https://habr.com/ru/post/282752/
All Articles