private void Update() { //Double tap to place object if (touchControls.DetectDoubleTap()) { PlaceObject(); } //Scroll with a single finger to rotate left/right, or to adjust height Vector2 scroll = touchControls.DetectScroll(); if (scroll.magnitude > 0.01f) { if (Mathf.Abs(scroll.x) > Mathf.Abs(scroll.y)) { indicator.transform.Rotate(new Vector3(0, -scroll.x, 0)); } else { heightOffset = Mathf.Clamp(heightOffset + (scroll.y / heightAdjustDamper), 0, 3); } } //Pinch with two fingers to resize float resize = touchControls.DetectPinch() / touchControls.pinchDamper; if (Mathf.Abs(resize) > 0.01f) { float x = Mathf.Clamp(indicator.transform.lossyScale.x + resize, touchControls.scaleMin, touchControls.scaleMax); float y = Mathf.Clamp(indicator.transform.lossyScale.y + resize, touchControls.scaleMin, touchControls.scaleMax); float z = Mathf.Clamp(indicator.transform.lossyScale.z + resize, touchControls.scaleMin, touchControls.scaleMax); indicator.transform.localScale = new Vector3(x, y, z); } UpdatePlacementLocation(); UpdateIndicator(); }
private void Update() { if (selected == null) { DetectObject(); if (touchControls.DetectDoubleTap() && target != null) { selected = target; selected.transform.SetParent(Camera.main.transform); kinematicBuffer = selected.GetComponent <Rigidbody>().isKinematic; selected.GetComponent <Rigidbody>().isKinematic = true; selected.GetComponent <Collider>().isTrigger = true; } } else if (selected != null && touchControls.DetectDoubleTap()) { selected.transform.SetParent(null); selected.GetComponent <Rigidbody>().isKinematic = kinematicBuffer; selected.GetComponent <Collider>().isTrigger = false; save.ChangeObject(selected); selected = null; } else { float deltaSize = touchControls.DetectPinch() / touchControls.pinchDamper; if (Mathf.Abs(deltaSize) > 0.01f) { float x = Mathf.Clamp(selected.transform.lossyScale.x + deltaSize, touchControls.scaleMin, touchControls.scaleMax); float y = Mathf.Clamp(selected.transform.lossyScale.y + deltaSize, touchControls.scaleMin, touchControls.scaleMax); float z = Mathf.Clamp(selected.transform.lossyScale.z + deltaSize, touchControls.scaleMin, touchControls.scaleMax); selected.transform.localScale = new Vector3(x, y, z); } Vector2 deltaScroll = touchControls.DetectScroll(); if (deltaScroll.magnitude > 0.1f) { Vector3 rot = touchControls.GetRotationFromScreenSpaceValue(deltaScroll, selected.transform); selected.transform.Rotate(rot * touchControls.rotateSensitivity); } float deltaSwivel = touchControls.DetectSwivel(); if (Mathf.Abs(deltaSwivel) > 0) { Vector3 fwdRot = touchControls.GetRotationFromSwivel(deltaSwivel, selected.transform); selected.transform.Rotate(fwdRot * touchControls.swivelSensitivity); } RaycastHit hit; Ray ray = new Ray(selected.transform.position, new Vector3(0, -1, 0)); if (Physics.Raycast(ray, out hit)) { raycastIndicator.SetActive(true); raycastIndicator.transform.position = hit.point; raycastLine.SetPositions(new Vector3[] { raycastIndicator.transform.position, selected.transform.position }); } else { raycastLine.SetPositions(new Vector3[] { raycastIndicator.transform.position, raycastIndicator.transform.position }); raycastIndicator.SetActive(false); } } }