How to fix code u-turn?

Good afternoon everyone, can anyone help with the code ? Code is supposed to do a reversal of the object along the Z axis and it works , I click on the object and rotate left/right , but every time I lift my finger and then click on the object he set in the place of my touch , and I need so I can continue to turn to the place where I released the click , and then it turns out every time a new turn. How not to try not able to customize the code , below the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ToucTurn : MonoBehaviour

[Header("Degree of rotation offset. *360")]
publicfloat offset = 0f;

Vector3 startDragDir;
Vector3 currentDragDir;
Quaternion initialRotation;
float angleFromStart;

void OnMouseDown()

startDragDir = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;

initialRotation = transform.rotation;

void OnMouseDrag()
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;

difference.Normalize( );

float rotationZ = Mathf.Atan2( difference.y, difference.x) * Mathf.Rad2Deg;

transform.rotation = Quaternion.Euler( 0f, 0f, rotationZ - (0 + offset) );
April 19th 20 at 12:07
0 answer

Find more questions by tags C#