public swipes swipe() { if (Input.touches.Length > 0) { Touch t = Input.GetTouch(0); if (t.phase == TouchPhase.Began) { firstPressPos = new Vector2(t.position.x, t.position.y); animator.StartPlayback(); } if (t.phase == TouchPhase.Ended) { secondPressPos = new Vector2(t.position.x, t.position.y); currentSwipe = new Vector2(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y); currentSwipe.Normalize(); if (currentSwipe.y > 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f) { lastswipe = swipes.up; return(swipes.up); } if (currentSwipe.y < 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f) { lastswipe = swipes.down; animator.StartPlayback(); return(swipes.down); } if (currentSwipe.x > 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f) { lastswipe = swipes.up; return(swipes.right); animator.StartPlayback(); } if (currentSwipe.x < 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f) { lastswipe = swipes.left; animator.StartPlayback(); return(swipes.left); } animator.StartPlayback(); return(swipes.up); } animator.StartPlayback(); return(swipes.none); } animator.StartPlayback(); return(swipes.none); }
public void OnPointerUp(PointerEventData eventData) { m_endTouch = eventData.position; Vector2 dir = Vector3.Normalize(new Vector3(m_endTouch.x - m_startTouch.x, m_endTouch.y - m_startTouch.y)); if (m_startTouch - m_endTouch != Vector2.zero) { if (Mathf.Abs(dir.x) > Mathf.Abs(dir.y)) { currentSwipe = (dir.x > 0) ? swipes.right : swipes.left; GameManager.instance.SwapCar(currentSwipe); } else { currentSwipe = (dir.y > 0) ? swipes.up : swipes.down; if (currentSwipe == swipes.down) { GameManager.instance.StartGame(); } } } }
public swipes swipe() { if (Input.touches.Length > 0) { Touch t = Input.GetTouch(0); if (t.phase == TouchPhase.Began && CrossPlatformInputManager.GetButton("Swipe")) { firstPressPos = new Vector2(t.position.x, t.position.y); animator.StartPlayback(); Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.gameObject.tag == "Enemy") { detectedObject = hit.collider.gameObject; detectedObject.GetComponent <EnemyController> ().onTap(); objectDetected = true; return(swipes.none); } if (hit.collider.gameObject.tag == "Cage") { detectedObject = hit.collider.gameObject; detectedObject.GetComponent <AnimalCageController> ().onTap(); objectDetected = true; return(swipes.none); } } } if (t.phase == TouchPhase.Ended) { secondPressPos = new Vector2(t.position.x, t.position.y); currentSwipe = new Vector2(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y); currentSwipe.Normalize(); if (currentSwipe.y > 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f) { lastswipe = swipes.up; return(swipes.up); } if (currentSwipe.y < 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f) { lastswipe = swipes.down; return(swipes.down); } if (currentSwipe.x > 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f) { lastswipe = swipes.up; return(swipes.right); } if (currentSwipe.x < 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f) { lastswipe = swipes.left; return(swipes.left); } //only move if havent touched object if (objectDetected == false) { //print ("tap"); return(swipes.tap); } objectDetected = false; } return(swipes.none); } return(swipes.none); }