void PuzzleMove() { Touch touch = Input.GetTouch(0); // Handle finger movements based on TouchPhase switch (touch.phase) { //When a touch has first been detected, change the message and record the starting position case TouchPhase.Began: if (GetObjectFromTouch() != null) { if (GetObjectFromTouch().tag == PuzzleTag) { Structure = GetObjectFromTouch(); Transform StructureParent = Structure.transform.parent; target = GetChildByName(StructureParent, TargetName); //StructureParent.GetComponent<SpriteMod>().ChangeRotation(); Structure.GetComponent <SpriteMod>().ChangeRotation(); touchTimer = Time.deltaTime; moveOfPuzzle = false; //structure = GetChildByName(GetObjectFromTouch().transform, SpriteName); } } //Do more here break; //Determine if the touch is a moving touch case TouchPhase.Moved: // Determine direction by comparing the current touch position with the initial one if (Structure != null && target != null && touchTimer + timeToRotate > Time.deltaTime) { target.transform.position = TouchPosToCameraPos(touch); truePos.x = target.transform.position.x; truePos.y = target.transform.position.y; Structure.transform.position = truePos; moveOfPuzzle = true; } break; case TouchPhase.Ended: // Report that the touch has ended when it ends if (Structure != null && target != null && moveOfPuzzle) { target.transform.position = TouchPosToCameraPos(touch); Debug.Log("Current " + truePos); //truePos.x = Mathf.Floor(target.transform.position.x / gridsize) * gridsize; //truePos.y = Mathf.Floor(target.transform.position.y / gridsize) * gridsize; truePos = CorrectToGrid(truePos); Debug.Log("After " + truePos); Structure.transform.position = truePos; touchTimer = 0f; } target = null; Structure = null; gridSystem.CheckAllGridAfterPuzzleMove(); puzzleMaster.WinCondition(); moveOfPuzzle = false; break; } }