How to use TouchDistance class of Input package

Best WinAppDriver code snippet using Input.TouchDistance

TouchInterface.cs

Source:TouchInterface.cs Github

copy

Full Screen

1using UnityEngine;2using System.Collections;3public class TouchInterface : MonoBehaviour {4 TouchManager touchManager;5 6 Vector3 touchPosition ;7 8 Vector2 touchDistance;9 float touchTime;10 bool gestureArmed;11 12 Transform startTarget;13 14 float tapTime = 0.25;15 float gestureTime = 0.25;16 float longTouchTime = 1;17 float swipeDistance = 30;18 19 function Start() {20 touchManager = GameObject.Find("TouchControl").GetComponent(TouchManager);21 22 }23 24 function Update() {25 if (Application.platform != RuntimePlatform.Android || Application.platform != RuntimePlatform.IPhonePlayer) {26 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);27 RaycastHit hit;28 Vector3 lastTouchPosition = touchPosition;29 touchPosition = Input.mousePosition;30 Vector2 touchDelta;31 touchDelta.x = touchPosition.x - lastTouchPosition.x;32 touchDelta.y = touchPosition.y - lastTouchPosition.y;33 touchPosition.z = Camera.main.transform.position.z;34 35 36 if (Input.GetMouseButtonDown(0)) {37 touchDelta = Vector2.zero;38 touchDistance = Vector2.zero;39 touchTime = 0;40 Physics.Raycast(ray, hit);41 touchManager.touchDown(hit.transform, touchPosition);42 startTarget = hit.transform;43 gestureArmed = true;44 }45 46 if (Input.GetMouseButton(0)) {47 Physics.Raycast(ray, hit);48 touchManager.touchDrag(touchDelta, touchDistance, touchPosition, hit.transform, startTarget);49 touchDistance += touchDelta;50 touchTime += Time.deltaTime;51 if (gestureArmed) {52 if (touchTime > longTouchTime) {53 if (startTarget == hit.transform) {54 touchManager.longTouched(startTarget);55 }56 gestureArmed = false;57 }58 }59 60 }61 62 if (Input.GetMouseButtonUp(0)) {63 Physics.Raycast(ray, hit);64 //print("touchUp");65 touchManager.touchUp(hit.transform, startTarget, touchPosition, normalizedDistance(touchDistance), touchTime);66 if (touchDistance.x < -swipeDistance && gestureArmed) {67 touchManager.swipeLeft(touchTime, startTarget, hit.transform);68 }69 if (touchDistance.x > swipeDistance && gestureArmed) {70 touchManager.swipeRight(touchTime, startTarget, hit.transform);71 }72 if (touchDistance.y < -swipeDistance && gestureArmed) {73 touchManager.swipeDown(touchTime, startTarget, hit.transform);74 }75 if (touchDistance.y > swipeDistance && gestureArmed) {76 touchManager.swipeUp(touchTime, startTarget, hit.transform);77 }78 startTarget = null;79 if (touchTime < tapTime) {80 touchManager.tap(hit.transform, touchPosition);81 }82 gestureArmed = false;83 84 } 85 86 } else {87 88 Touch[] touchInput = Input.touches;89 90 if (touchInput.Length > 0) { 91 Touch touch = touchInput[0];92 ray = Camera.main.ScreenPointToRay(touch.position);93 94 lastTouchPosition = touchPosition;95 touchPosition = touch.position;96 97 touchDelta.x = touchPosition.x - lastTouchPosition.x;98 touchDelta.y = touchPosition.y - lastTouchPosition.y;99 touchPosition.z = Camera.main.transform.position.z;100 101 102 if (touch.phase == TouchPhase.Began) { 103 touchDelta = Vector2.zero;104 touchDistance = Vector2.zero;105 touchTime = 0;106 Physics.Raycast(ray, hit);107 touchManager.touchDown(hit.transform, touchPosition);108 startTarget = hit.transform;109 gestureArmed = true;110 }111 112 if (touchInput.Length > 0) {113 Physics.Raycast(ray, hit);114 touchManager.touchDrag(touchDelta, touchDistance, touchPosition, hit.transform, startTarget);115 touchDistance += touchDelta;116 touchTime += Time.deltaTime;117 118 if (gestureArmed) {119 if (touchTime > gestureTime) {120 if (startTarget == hit.transform && (touchDistance.x + touchDistance.y) < 5) {121 touchManager.longTouched(startTarget);122 gestureArmed = false;123 } else {124 touchManager.longTouched(null);125 }126 gestureArmed = false;127 }128 }129 }130 131 if (touch.phase == TouchPhase.Ended) { 132 Physics.Raycast(ray, hit);133 touchManager.touchUp(hit.transform, startTarget, touchPosition, touchDistance, touchTime);134 135 if (gestureArmed) {136 touchManager.tap(hit.transform, touchPosition);137 if (touchDistance.x < -swipeDistance) {138 139 if (touchInput.Length > 2) {140 // touchManager.sweepLeft();141 return; 142 }143 touchManager.swipeLeft(touchTime, startTarget, hit.transform);144 }145 if (touchDistance.x > swipeDistance) {146 if (touchInput.Length > 2) {147 // touchManager.sweepRight();148 return; 149 }150 touchManager.swipeRight(touchTime, startTarget, hit.transform);151 }152 if (touchDistance.y < -swipeDistance) {153 if (touchInput.Length > 2) {154 // touchManager.sweepDown();155 return; 156 } 157 touchManager.swipeDown(touchTime, startTarget, hit.transform);158 }159 if (touchDistance.y > swipeDistance) {160 if (touchInput.Length > 2) {161 // touchManager.sweepUp();162 return; 163 } 164 touchManager.swipeUp(touchTime, startTarget, hit.transform);165 }166 }167 startTarget = null;168 gestureArmed = false;169 }170 }171 }172 173 if (Input.GetKeyUp(KeyCode.Escape)) {174 touchManager.backPressed();175 }176 if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.Menu)) {177 touchManager.menuPressed();178 }179 180 }181 182 183 Vector2 normalizedDistance(Vector2 distance) {184 Vector2 newDistance = Vector2((distance.x/Screen.width), (distance.y/Screen.height));185 return newDistance;186 }187}...

Full Screen

Full Screen

Inputs.cs

Source:Inputs.cs Github

copy

Full Screen

...4using UnityEngine;5using UnityEngine.Serialization;6public class Inputs : MonoBehaviour7{8 private float oldTouchDistance = 0;9 private float touchDistance;10 [SerializeField]11 private GameObject cameraObject;12 private RaycastHit hit;13 private Boolean animationRunning = false;14 15 // Update is called once per frame16 void Update()17 {18 animationRunning = GetComponent<Assembly>().getAnimationBool();19 zoomCheck();20 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);21 try22 {23 if (Input.GetKeyDown(KeyCode.Mouse0))24 {25 if (Physics.Raycast(ray,out hit))26 {27 if (hit.collider.CompareTag("resetCam"))28 {29 cameraObject.GetComponent<CameraController>().centerCamera();30 }31 if (!animationRunning && hit.collider.CompareTag("prevStep"))32 {33 cameraObject.GetComponent<CameraController>().centerCamera();34 }35 if(hit.collider.CompareTag("Finish"))36 {37 hit = new RaycastHit();38 GetComponent<Assembly>().finishBuild();39 }40 }41 }42 }43 catch (Exception e)44 {45 Console.WriteLine(e);46 throw;47 }48 49 50 }51 private void calculateTouchDistance()52 {53 Vector2 touch0, touch1;54 touch0 = Input.GetTouch(0).position;55 touch1 = Input.GetTouch(1).position;56 touchDistance = Vector2.Distance(touch0, touch1);57 }58 private void zoomCheck()59 {60 if (Input.touchCount >= 2)61 {62 calculateTouchDistance();63 if (touchDistance > oldTouchDistance)64 {65 cameraObject.GetComponent<CameraController>().zoomIn();66 oldTouchDistance = touchDistance;67 }else if (touchDistance<oldTouchDistance)68 {69 cameraObject.GetComponent<CameraController>().zoomOut();70 oldTouchDistance = touchDistance;71 }72 }73 }74}...

Full Screen

Full Screen

PinchGesture.cs

Source:PinchGesture.cs Github

copy

Full Screen

1namespace Lime2{3 public sealed class PinchGesture : DragGesture4 {5 public float TouchDistance { get; private set; }6 public float TouchPressDistance { get; private set; }7 public float TotalPinchScale => TouchDistance / TouchPressDistance;8 public float LastPinchScale { get; private set; }9 private Vector2 Touch0 => Input.GetTouchPosition(0);10 private Vector2 Touch1 => Input.GetTouchPosition(1);11 public PinchGesture() : this(DragDirection.Any, exclusive: false, DefaultDragThreshold)12 {13 }14 public PinchGesture(DragDirection dragDirection)15 : this(dragDirection, exclusive: false, DefaultDragThreshold)16 {17 }18 public PinchGesture(bool exclusive)19 : this(DragDirection.Any, exclusive, DefaultDragThreshold)20 {21 }22 public PinchGesture(DragDirection direction, bool exclusive, float dragThreshold)23 : base(0, direction, exclusive, dragThreshold)24 {25 }26 protected internal override void Update(float delta)27 {28 base.Update(delta);29 if (WasBegan()) {30 TouchPressDistance = Vector2.Distance(Touch0, Touch1);31 TouchDistance = TouchPressDistance;32 } else if (IsChanging()) {33 float previousTouchDistance = TouchDistance;34 TouchDistance = Vector2.Distance(Touch0, Touch1);35 LastPinchScale = TouchDistance / previousTouchDistance;36 if (LastPinchScale != 1.0f) {37 RaiseChanged();38 LastPinchScale = 1.0f;39 }40 }41 }42 protected override bool TryGetStartDragPosition(out Vector2 position)43 {44 return TryGetDragPosition(out position);45 }46 protected override bool TryGetDragPosition(out Vector2 position)47 {48 if (IsDragging()) {49 position = (Touch0 + Touch1) * 0.5f;50 return true;51 }52 position = Vector2.NaN;53 return false;54 }55 protected override bool IsDragging()56 {57 return Input.GetNumTouches() == 2;58 }59 protected override bool CanStartDrag()60 {61 return62 (MousePosition - MousePressPosition).SqrLength > DragThreshold.Sqr() ||63 TouchDistance != Vector2.Distance(Touch0, Touch1);64 }65 }66}...

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2using UnityEngine.InputSystem;3using UnityEngine.InputSystem.EnhancedTouch;4using UnityEngine.InputSystem.Touch;5{6 void Start()7 {8 EnhancedTouchSupport.Enable();9 }10 void Update()11 {12 if (Touchscreen.current != null)13 {14 Touch primaryTouch = Touchscreen.current.primaryTouch;15 if (primaryTouch != null)16 {17 Debug.Log("Touch:" + primaryTouch.position.ReadValue());18 }19 }20 }21}22using UnityEngine;23using UnityEngine.InputSystem;24{25 void Start()26 {27 InputSystem.EnableDevice(Touchscreen.current);28 }29 void Update()30 {31 if (Touchscreen.current != null)32 {33 Touch primaryTouch = Touchscreen.current.primaryTouch;34 if (primaryTouch != null)35 {36 Debug.Log("Touch:" + primaryTouch.position.ReadValue());37 }38 }39 }40}

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2using UnityEngine.InputSystem;3{4 public GameObject touch1;5 public GameObject touch2;6 public GameObject touch3;7 public GameObject touch4;8 public GameObject touch5;9 public GameObject touch6;10 public GameObject touch7;11 public GameObject touch8;12 public GameObject touch9;13 public GameObject touch10;14 public GameObject touch11;15 public GameObject touch12;16 public GameObject touch13;17 public GameObject touch14;18 public GameObject touch15;19 public GameObject touch16;20 public GameObject touch17;21 public GameObject touch18;22 public GameObject touch19;23 public GameObject touch20;24 public GameObject touch21;25 public GameObject touch22;26 public GameObject touch23;27 public GameObject touch24;28 public GameObject touch25;29 public GameObject touch26;30 public GameObject touch27;31 public GameObject touch28;32 public GameObject touch29;33 public GameObject touch30;34 public GameObject touch31;35 public GameObject touch32;36 public GameObject touch33;37 public GameObject touch34;38 public GameObject touch35;39 public GameObject touch36;40 public GameObject touch37;41 public GameObject touch38;42 public GameObject touch39;43 public GameObject touch40;44 public GameObject touch41;45 public GameObject touch42;46 public GameObject touch43;47 public GameObject touch44;48 public GameObject touch45;49 public GameObject touch46;50 public GameObject touch47;51 public GameObject touch48;52 public GameObject touch49;53 public GameObject touch50;54 public GameObject touch51;55 public GameObject touch52;56 public GameObject touch53;57 public GameObject touch54;58 public GameObject touch55;59 public GameObject touch56;60 public GameObject touch57;61 public GameObject touch58;62 public GameObject touch59;63 public GameObject touch60;64 public GameObject touch61;65 public GameObject touch62;66 public GameObject touch63;67 public GameObject touch64;68 public GameObject touch65;69 public GameObject touch66;70 public GameObject touch67;71 public GameObject touch68;72 public GameObject touch69;73 public GameObject touch70;74 public GameObject touch71;75 public GameObject touch72;76 public GameObject touch73;77 public GameObject touch74;78 public GameObject touch75;79 public GameObject touch76;80 public GameObject touch77;81 public GameObject touch78;82 public GameObject touch79;83 public GameObject touch80;

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2{3 private Vector2 touchStartPos;4 private Vector2 touchEndPos;5 private float distance;6 private void Update()7 {8 if (Input.touchCount > 0)9 {10 Touch touch = Input.GetTouch(0);11 if (touch.phase == TouchPhase.Began)12 {13 touchStartPos = touch.position;14 }15 if (touch.phase == TouchPhase.Ended)16 {17 touchEndPos = touch.position;18 distance = Vector2.Distance(touchStartPos, touchEndPos);19 }20 }21 }22}23using UnityEngine;24{25 private Vector2 touchStartPos;26 private Vector2 touchEndPos;27 private float distance;28 private void Update()29 {30 if (Input.touchCount > 0)31 {32 Touch touch = Input.GetTouch(0);33 if (touch.phase == TouchPhase.Began)34 {35 touchStartPos = touch.position;36 }37 if (touch.phase == TouchPhase.Ended)38 {39 touchEndPos = touch.position;40 distance = Vector2.Distance(touchStartPos, touchEndPos);41 }42 }43 }44}45using UnityEngine;46{47 private Vector2 touchStartPos;48 private Vector2 touchEndPos;49 private float distance;50 private void Update()51 {52 if (Input.touchCount > 0)53 {54 Touch touch = Input.GetTouch(0);55 if (touch.phase == TouchPhase.Began)56 {57 touchStartPos = touch.position;58 }59 if (touch.phase == TouchPhase.Ended)60 {61 touchEndPos = touch.position;62 distance = Vector2.Distance(touchStartPos, touchEndPos);63 }64 }65 }66}67using UnityEngine;68{69 private Vector2 touchStartPos;70 private Vector2 touchEndPos;71 private float distance;72 private void Update()73 {74 if (Input.touchCount > 0)75 {76 Touch touch = Input.GetTouch(0);77 if (touch.phase

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2using UnityEngine.InputSystem;3{4 public float distance;5 public float distance2;6 public float distance3;7 public float distance4;8 public float distance5;9 public float distance6;10 public float distance7;11 public float distance8;12 public float distance9;13 public float distance10;14 public float distance11;15 public float distance12;16 public float distance13;17 public float distance14;18 public float distance15;19 public float distance16;20 public float distance17;21 public float distance18;22 public float distance19;23 public float distance20;24 public float distance21;25 public float distance22;26 public float distance23;27 public float distance24;28 public float distance25;29 public float distance26;30 public float distance27;31 public float distance28;32 public float distance29;33 public float distance30;34 public float distance31;35 public float distance32;36 public float distance33;37 public float distance34;38 public float distance35;39 public float distance36;40 public float distance37;41 public float distance38;42 public float distance39;43 public float distance40;44 public float distance41;45 public float distance42;46 public float distance43;47 public float distance44;48 public float distance45;49 public float distance46;50 public float distance47;51 public float distance48;52 public float distance49;53 public float distance50;54 public float distance51;55 public float distance52;56 public float distance53;57 public float distance54;58 public float distance55;59 public float distance56;60 public float distance57;61 public float distance58;62 public float distance59;63 public float distance60;64 public float distance61;65 public float distance62;66 public float distance63;67 public float distance64;68 public float distance65;69 public float distance66;70 public float distance67;71 public float distance68;72 public float distance69;73 public float distance70;74 public float distance71;75 public float distance72;76 public float distance73;77 public float distance74;78 public float distance75;79 public float distance76;80 public float distance77;81 public float distance78;82 public float distance79;83 public float distance80;

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine.InputSystem;2using UnityEngine;3{4 public float distance;5 private void Update()6 {7 if (Input.touchCount == 2)8 {9 var touchZero = Input.GetTouch(0);10 var touchOne = Input.GetTouch(1);11 var touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;12 var touchOnePrevPos = touchOne.position - touchOne.deltaPosition;13 var prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;14 var touchDeltaMag = (touchZero.position - touchOne.position).magnitude;15 var deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;16 distance = deltaMagnitudeDiff;17 print(distance);18 }19 }20}21using UnityEngine;22using UnityEngine.UI;23{24 public Text text;25 public float distance;26 private void Update()27 {28 if (Input.touchCount == 2)29 {30 var touchZero = Input.GetTouch(0);31 var touchOne = Input.GetTouch(1);32 var touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;33 var touchOnePrevPos = touchOne.position - touchOne.deltaPosition;34 var prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;35 var touchDeltaMag = (touchZero.position - touchOne.position).magnitude;36 var deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;37 distance = deltaMagnitudeDiff;38 text.text = distance.ToString();39 }40 }41}42using UnityEngine;43using UnityEngine.UI;44{45 public Text text;46 public float distance;47 public float distance2;48 private void Update()49 {50 if (Input.touchCount == 2)51 {52 var touchZero = Input.GetTouch(0);53 var touchOne = Input.GetTouch(1);54 var touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;55 var touchOnePrevPos = touchOne.position - touchOne.deltaPosition;56 var prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;57 var touchDeltaMag = (touchZero.position - touchOne.position).magnitude;

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using System.Collections;2using System.Collections.Generic;3using UnityEngine;4using UnityEngine.UI;5using UnityEngine.InputSystem;6{7 public Text touchDistanceText;8 private Touchscreen touchscreen;9 private TouchControl touch1;10 private TouchControl touch2;11 private void Awake()12 {13 touchscreen = InputSystem.GetDevice<Touchscreen>();14 touch1 = touchscreen.primaryTouch;15 touch2 = touchscreen.secondaryTouch;16 }17 void Update()18 {19 if (touch1.isPressed && touch2.isPressed)20 {21 Vector2 touch1Position = touch1.position.ReadValue();22 Vector2 touch2Position = touch2.position.ReadValue();23 float distance = Vector2.Distance(touch1Position, touch2Position);24 touchDistanceText.text = "Touch Distance: " + distance;25 }26 }27}28using System.Collections;29using System.Collections.Generic;30using UnityEngine;31using UnityEngine.InputSystem;32{33 private Touchscreen touchscreen;34 private TouchControl touch1;35 private TouchControl touch2;36 private void Awake()37 {38 touchscreen = InputSystem.GetDevice<Touchscreen>();39 touch1 = touchscreen.primaryTouch;40 touch2 = touchscreen.secondaryTouch;41 }42 void Update()43 {44 if (touch1.isPressed && touch2.isPressed)45 {46 Vector2 touch1Position = touch1.position.ReadValue();47 Vector2 touch2Position = touch2.position.ReadValue();48 float distance = Vector2.Distance(touch1Position, touch2Position);49 Debug.Log("Touch Distance: " + distance);50 }51 }52}53using System.Collections;54using System.Collections.Generic;55using UnityEngine;56using UnityEngine.InputSystem;57{58 private Touchscreen touchscreen;59 private TouchControl touch1;60 private TouchControl touch2;61 private void Awake()62 {63 touchscreen = InputSystem.GetDevice<Touchscreen>();64 touch1 = touchscreen.primaryTouch;65 touch2 = touchscreen.secondaryTouch;66 }67 void Update()68 {69 if (touch1.isPressed && touch2.isPressed)70 {71 Vector2 touch1Position = touch1.position.ReadValue();72 Vector2 touch2Position = touch2.position.ReadValue();

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2using UnityEngine.InputSystem;3{4 private Touch touch;5 private Vector2 touchPos;6 private float touchDistance;7 private void Update()8 {9 if (Input.touchCount == 1)10 {11 touch = Input.GetTouch(0);12 if (touch.phase == TouchPhase.Began)13 {14 touchPos = touch.position;15 }16 if (touch.phase == TouchPhase.Moved)17 {18 touchDistance = Vector2.Distance(touch.position, touchPos);19 }20 if (touch.phase == TouchPhase.Ended)21 {22 touchDistance = Vector2.Distance(touch.position, touchPos);23 }24 }25 }26}27using UnityEngine;28using UnityEngine.InputSystem;29{30 private Touch touch;31 private Vector2 touchPos;32 private float touchDistance;33 private void Update()34 {35 if (Input.touchCount == 1)36 {37 touch = Input.GetTouch(0);38 if (touch.phase == TouchPhase.Began)39 {40 touchPos = touch.position;41 }42 if (touch.phase == TouchPhase.Moved)43 {44 touchDistance = Vector2.Distance(touch.position, touchPos);45 }46 if (touch.phase == TouchPhase.Ended)47 {48 touchDistance = Vector2.Distance(touch.position, touchPos);49 }50 }51 }52}53using UnityEngine;54using UnityEngine.InputSystem;55{56 private Touch touch;57 private Vector2 touchPos;58 private float touchDistance;59 private void Update()60 {61 if (Input.touchCount == 1)62 {63 touch = Input.GetTouch(0);64 if (touch.phase == TouchPhase.Began)65 {66 touchPos = touch.position;67 }68 if (touch.phase == TouchPhase.Moved)69 {70 touchDistance = Vector2.Distance(touch.position, touchPos);71 }72 if (touch.phase == TouchPhase.Ended)73 {74 touchDistance = Vector2.Distance(touch.position, touchPos);75 }76 }77 }78}79using UnityEngine;80using UnityEngine.InputSystem;

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2using UnityEngine.InputSystem;3{4 public float touchDistance;5 public float touchDistanceX;6 public float touchDistanceY;7 private Vector3 touchStartPos;8 private Vector3 touchEndPos;9 private void Update()10 {11 if (Input.touchCount > 0)12 {13 Touch touch = Input.GetTouch(0);14 if (touch.phase == TouchPhase.Began)15 {16 touchStartPos = touch.position;17 }18 if (touch.phase == TouchPhase.Ended)19 {20 touchEndPos = touch.position;21 touchDistance = Vector3.Distance(touchStartPos, touchEndPos);22 touchDistanceX = Mathf.Abs(touchStartPos.x - touchEndPos.x);23 touchDistanceY = Mathf.Abs(touchStartPos.y - touchEndPos.y);24 }25 }26 }27}28using UnityEngine;29using UnityEngine.InputSystem;30{31 public float touchDistance;32 public float touchDistanceX;33 public float touchDistanceY;34 private Vector3 touchStartPos;35 private Vector3 touchEndPos;36 private void Update()37 {38 if (Input.touchCount > 0)39 {40 Touch touch = Input.GetTouch(0);41 if (touch.phase == TouchPhase.Began)42 {43 touchStartPos = touch.position;44 }45 if (touch.phase == TouchPhase.Ended)46 {47 touchEndPos = touch.position;48 touchDistance = Vector3.Distance(touchStartPos, touchEndPos);49 touchDistanceX = Mathf.Abs(touchStartPos.x - touchEndPos.x);50 touchDistanceY = Mathf.Abs(touchStartPos.y - touchEndPos.y);51 }52 }53 }54}55using UnityEngine;56using UnityEngine.InputSystem;57{58 public float touchDistance;59 public float touchDistanceX;60 public float touchDistanceY;61 private Vector3 touchStartPos;62 private Vector3 touchEndPos;63 private void Update()64 {65 if (Input.touchCount > 0)66 {67 Touch touch = Input.GetTouch(0);68 if (touch.phase == TouchPhase.Began)69 {

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2using UnityEngine.UI;3using UnityEngine.InputSystem;4using UnityEngine.InputSystem.UI;5{6 public Text text;7 public InputActionReference touchAction;8 public InputActionReference pointerAction;9 public InputActionReference dragAction;10 public InputActionReference clickAction;11 private void OnEnable()12 {13 touchAction.action.performed += Touch;14 pointerAction.action.performed += Pointer;15 dragAction.action.performed += Drag;16 clickAction.action.performed += Click;17 }18 private void OnDisable()19 {20 touchAction.action.performed -= Touch;21 pointerAction.action.performed -= Pointer;22 dragAction.action.performed -= Drag;23 clickAction.action.performed -= Click;24 }25 private void Click(InputAction.CallbackContext obj)26 {27 text.text = "Click";28 }29 private void Drag(InputAction.CallbackContext obj)30 {31 text.text = "Drag";32 }33 private void Pointer(InputAction.CallbackContext obj)34 {35 text.text = "Pointer";36 }37 private void Touch(InputAction.CallbackContext obj)38 {39 text.text = "Touch";40 }41}42using UnityEngine;43using UnityEngine.InputSystem;44using UnityEngine.InputSystem.UI;45{46 public InputActionReference touchAction;47 public InputActionReference pointerAction;48 public InputActionReference dragAction;49 public InputActionReference clickAction;50 private void OnEnable()51 {52 touchAction.action.performed += Touch;53 pointerAction.action.performed += Pointer;54 dragAction.action.performed += Drag;55 clickAction.action.performed += Click;56 }57 private void OnDisable()58 {59 touchAction.action.performed -= Touch;60 pointerAction.action.performed -= Pointer;61 dragAction.action.performed -= Drag;62 clickAction.action.performed -= Click;63 }64 private void Click(InputAction.CallbackContext obj)65 {66 Debug.Log("Click");67 }68 private void Drag(InputAction.CallbackContext obj)69 {70 Debug.Log("Drag");71 }72 private void Pointer(InputAction.CallbackContext obj)73 {74 Debug.Log("Pointer");75 }76 private void Touch(InputAction.CallbackContext obj)77 {78 Debug.Log("Touch");79 }80}

Full Screen

Full Screen

TouchDistance

Using AI Code Generation

copy

Full Screen

1using UnityEngine;2using UnityEngine.InputSystem;3{4 public float distance;5 public float maxDistance = 20f;6 public float minDistance = 0.5f;7 private Touch touch;8 private Vector2 touchPosition;9 private Vector2 touchPositionPre;10 private Vector2 touchPositionPrepre;11 private float touchDelta;12 private float touchDeltaPre;13 private float touchDeltaPrepre;14 private float touchDeltaAverage;15 private float touchDeltaAveragePre;16 private float touchDeltaAveragePrepre;17 private float touchDeltaAveragePreprepre;18 private float touchDeltaAveragePrepreprepre;19 private float touchDeltaAveragePreprepreprepre;20 private float touchDeltaAveragePrepreprepreprepre;21 private float touchDeltaAveragePreprepreprepreprepre;22 private float touchDeltaAveragePrepreprepreprepreprepre;23 private float touchDeltaAveragePreprepreprepreprepreprepre;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run WinAppDriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful