public void Update() { Vector3 touchPosition; if (!GetTouchPosition(out touchPosition)) { return; } PlayTouchEffect(touchPosition); if (!TryTouchExistingCharacter(touchPosition)) { StartCoroutine(_tangoTouchProjector.Touch(touchPosition, ArTouchAction)); } }
// Update is called once per frame void Update() { foreach (Touch touch in Input.touches) { int i = touch.fingerId; Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit; switch (touch.phase) { case TouchPhase.Began: if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { // if (Physics.Raycast (ray, out hit, 100, layer)) { if (hit.collider != null) { screenPoint [i] = Camera.main.WorldToScreenPoint(hit.transform.gameObject.transform.position); offset [i] = hit.transform.gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, screenPoint [i].z)); selectedObj [i] = hit.transform.gameObject; if (selectedObj [i].tag == "Icecream" || selectedObj [i].tag == "Milk" || selectedObj [i].tag == "Sugar") { selectedObj [i].GetComponent <Food> ().ready = true; } else if (selectedObj [i].tag == "Insulin") { selectedObj [i].GetComponent <Insulin> ().ready = true; } else if (selectedObj [i].tag == "Meter") { selectedObj [i].GetComponent <GlucoseMeter> ().ready = true; } } } else { if (LevelTemplate.S.curLevel != 2) { PlayTouchEffect(touch.position); StartCoroutine(_tangoTouchProjector.Touch(touch.position, SetCharPos)); } } break; case TouchPhase.Moved: if (selectedObj [i] != null) { Vector3 curScreenPoint = new Vector3(touch.position.x, touch.position.y, screenPoint [i].z); Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset [i]; selectedObj [i].transform.position = curPosition; print("Obj " + i + " dragged"); } break; case TouchPhase.Ended: if (selectedObj [i].tag == "Icecream" || selectedObj [i].tag == "Milk" || selectedObj [i].tag == "Sugar") { selectedObj [i].GetComponent <Food> ().ready = false; } else if (selectedObj [i].tag == "Insulin") { selectedObj [i].GetComponent <Insulin> ().ready = false; } else if (selectedObj [i].tag == "Meter") { selectedObj [i].GetComponent <GlucoseMeter> ().ready = false; } selectedObj [i] = null; break; } } }