void Update() { if (TouchStarted()) { var pos = GetTouchPostion(); var hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(pos), Vector2.zero, 10f, LayerMask.GetMask(TARGET_LAYERMASK)); if (hitInfo) { var part = hitInfo.collider.gameObject.GetComponent <PartOfPlane>(); if (part != null) { touchedPart = part; } } } if (TouchFinished()) { if (touchedPart != null) { touchedPart.Plane.PartRelease(); touchedPart = null; } } if (touchedPart != null) { var newPos = Camera.main.ScreenToWorldPoint(GetTouchPostion()); if (touchedPart.Plane != null) { touchedPart.Plane.PartDragged(touchedPart, newPos); } } }
public void PartDragged(PartOfPlane part, Vector3 draggedPos) { draggedPos.z = transform.position.z; if (!isPartDrag) { draggingDelta = draggedPos - part.transform.position; isPartDrag = true; } var dir = draggedPos - transform.position - draggingDelta; float angle = Vector3.SignedAngle(part.transform.position - transform.position, dir, Vector3.forward); rotationDelta = new Vector3(0, 0, angle); }