GameObject CheckTouchingUI(MobileTouch newTouch) { // Reset selected GO newTouch.currentSelectedGO = null; // Set up the new Pointer Event m_PointerEventData = new PointerEventData(m_EventSystem); m_PointerEventData.position = newTouch.lastTouchedPos; // Raycast using Graphics Raycaster for UI List <RaycastResult> results = new List <RaycastResult>(); m_Raycaster.Raycast(m_PointerEventData, results); //For every result returned, output the name of the GameObject on the Canvas hit by the Ray foreach (RaycastResult result in results) { Debug.Log("Hit " + result.gameObject.name); // Attach the collided GO newTouch.currentSelectedGO = result.gameObject; // To make sure only detect the first UI Hit break; } // return result return(newTouch.currentSelectedGO); }
GameObject CheckTouchingGO(MobileTouch newTouch, int layerMaskID = 0) { // Reset selected GO newTouch.currentSelectedGO = null; // If it hits something... RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(newTouch.lastTouchedPos), Vector2.zero, 20.0f, 1 << layerMaskID); if (hit.collider != null) { newTouch.currentSelectedGO = hit.transform.gameObject; Debug.Log("Raycast2D hit: " + newTouch.currentSelectedGO.name); } return(newTouch.currentSelectedGO); }
// Update is called once per frame void Update() { MoveVector = PoolInput(); portal = GameObject.Find("door(Clone)").GetComponent <Portal>(); moveBool = portal.userBool; if (moveBool) { Move(); } Jump(); try { moveCamera = GameObject.Find("RotateCamera").GetComponent <MobileTouch>(); transform.Rotate(0, moveCamera.movePos, 0); } catch (System.NullReferenceException e) { } }
private void Awake() { if (m_Instance != null) // Make this a public Instance { Destroy(gameObject); return; } m_Instance = this; DontDestroyOnLoad(gameObject); SceneManager.activeSceneChanged += ActiveSceneChanged; // Create new MobileTouch and add into list MobileTouch newTouch = new MobileTouch(); MobileTouch newTouch2 = new MobileTouch(); MobileTouch newTouch3 = new MobileTouch(); MobileTouch newTouch4 = new MobileTouch(); m_listOfActiveTouches.Add(newTouch); m_listOfActiveTouches.Add(newTouch2); m_listOfActiveTouches.Add(newTouch3); m_listOfActiveTouches.Add(newTouch4); }
private void Update() { // Any touches on the screen if (Input.touchCount < 1) { return; } MobileTouch activeTouch = null; for (int i = 0; i < Input.touches.Length; ++i) { activeTouch = GetMobileTouch(Input.touches[i].fingerId); // React differently to different states switch (Input.touches[i].phase) { case TouchPhase.Began: // A new Touch just touched the screen { MobileTouch newTouch = GetDeactivatedMobileTouch(); // Activate the Touch Object newTouch.ActivateTouch(Input.touches[i].fingerId); newTouch.startTouchPos = Input.touches[i].position; newTouch.lastTouchedPos = newTouch.startTouchPos; //Debug.Log(i + ": ENTERED"); } break; case TouchPhase.Moved: // Touch moved on the screen { //CheckCollidedWithGO(activeTouch); activeTouch.lastTouchedPos = Input.touches[i].position; activeTouch.swipeDelta = Input.touches[i].deltaPosition; // Passed Deadzone? if (activeTouch.swipeDelta.sqrMagnitude < (15 * 15)) { activeTouch.swipeDelta = Vector2.zero; activeTouch.isSwiping = false; break; } // Check which direction was the largest activeTouch.isSwiping = true; if (Mathf.Abs(activeTouch.swipeDelta.x) > Mathf.Abs(activeTouch.swipeDelta.y)) { // Left or Right if (activeTouch.swipeDelta.x < 0) { activeTouch.swipeLeft = true; //Debug.Log(i + ": LEFTT"); } else { activeTouch.swipeRight = true; //Debug.Log(i + ": RIGHTTT"); } } else { // Up or Down if (activeTouch.swipeDelta.y < 0) { activeTouch.swipeDown = true; //Debug.Log(i + ": DOOWN"); } else { activeTouch.swipeUp = true; //Debug.Log(i + ": UPP"); } } } break; case TouchPhase.Stationary: // Still touching the screen, but hasn’t moved since the last frame { activeTouch.lastTouchedPos = Input.touches[i].position; //Debug.Log(Camera.main.ScreenToViewportPoint(activeTouch.lastTouchedPos)); } break; case TouchPhase.Ended: case TouchPhase.Canceled: { activeTouch.DeactivateTouch(); } break; } } }