// Update is called once per frame void Update() { if (Input.GetMouseButton(0) || Input.touchCount > 0) { Debug.Log("Touched"); Vector3 camPos = camera.transform.position; Vector3 camDirection = camera.transform.forward; Quaternion camRotation = camera.transform.rotation; float spawnDistance = 2; Debug.Log("Touched" + camPos.x + " " + camPos.y + " " + camPos.z); Vector3 spawnPos = camPos + (camDirection * spawnDistance); GameObject cur = Instantiate(gameObject, spawnPos, camRotation); cur.transform.SetParent(this.transform); } }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0) || Input.GetTouch(0).phase == TouchPhase.Began) { isTouchingUI = EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId); if (isTouchingUI) { Debug.Log("Dont Draw"); Debug.Log(Input.GetTouch(0)); } else if (!isTouchingUI && Input.touchCount > 0) { Draw(); Debug.Log("Draw"); } } }
// check for input action (phone touch) private void CheckForInputAction() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); bool bInputAction = true; switch (touch.phase) { case TouchPhase.Began: inputAction = MultiARInterop.InputAction.Click; inputNavCoordinates = Vector3.zero; startInputPos = touch.position; startTimestamp = lastFrameTimestamp; break; case TouchPhase.Moved: case TouchPhase.Stationary: if ((lastFrameTimestamp - startTimestamp) >= 0.25) { inputAction = MultiARInterop.InputAction.Grip; float screenMinDim = Screen.width < Screen.height ? Screen.width : Screen.height; Vector3 mouseRelPos = touch.position - startInputPos; inputNavCoordinates = mouseRelPos / screenMinDim; } break; case TouchPhase.Ended: inputAction = MultiARInterop.InputAction.Release; break; default: bInputAction = false; break; } if (bInputAction) { inputPos = touch.position; inputTimestamp = lastFrameTimestamp; } } else { #if UNITY_EDITOR bool bInputAction = true; if (Input.GetMouseButtonDown(0)) { inputAction = MultiARInterop.InputAction.Click; startInputPos = Input.mousePosition; startTimestamp = lastFrameTimestamp; } else if (Input.GetMouseButton(0)) { if ((lastFrameTimestamp - startTimestamp) >= 0.25) { inputAction = MultiARInterop.InputAction.Grip; //Vector3 screenSize = new Vector3(Screen.width, Screen.height, 0f); float screenMinDim = Screen.width < Screen.height ? Screen.width : Screen.height; Vector3 mouseRelPos = Input.mousePosition - (Vector3)startInputPos; inputNavCoordinates = mouseRelPos / screenMinDim; // new Vector3(mouseRelPos.x / screenSize.x, mouseRelPos.y / screenSize.y, 0f); } } else if (Input.GetMouseButtonUp(0)) { inputAction = MultiARInterop.InputAction.Release; } else { bInputAction = false; } if (bInputAction) { inputPos = Input.mousePosition; inputTimestamp = lastFrameTimestamp; } #endif } }