title: How to bringback an object to its original position after rotation in unity?
body: <p>I have created a project where a cube is rotated when we touch on it. I want the cube to return back to its original position when the user stops touching the cube. Below I have added the source code of rotating a cube:</p>
  
  <pre><code>using UnityEngine;
  
  using System.Collections;
  
  [RequireComponent(typeof(MeshRenderer))]
  
  public class dr : MonoBehaviour 
  {
  
      #region ROTATE
      private float _sensitivity = 1f;
      private Vector3 _mouseReference;
      private Vector3 _mouseOffset;
      private Vector3 _rotation = Vector3.zero;
      private bool _isRotating;
  
  
      #endregion
  
      void Update()
      {
          if(_isRotating)
          {
              // offset
              _mouseOffset = (Input.mousePosition - _mouseReference); // apply rotation
              _rotation.y = -(_mouseOffset.x + _mouseOffset.y) * _sensitivity; // rotate
              gameObject.transform.Rotate(_rotation); // store new mouse position
              _mouseReference = Input.mousePosition;
          }
  
      }
  
      void OnMouseDown()
      {
          // rotating flag
          _isRotating = true;
  
          // store mouse position
          _mouseReference = Input.mousePosition;
      }
  
      void OnMouseUp()
      {
          // rotating flag
          _isRotating = false;
      }
  
  }
  </code></pre>
  
  <p>edited code:-
  using UnityEngine;
  using System.Collections;</p>
  
  <p>[RequireComponent(typeof(MeshRenderer))]</p>
  
  <p>public class pt : MonoBehaviour 
  {</p>
  
  <pre><code>#region ROTATE
  private float _sensitivity = 1f;
  private Vector3 _mouseReference;
  private Vector3 _mouseOffset;
  private Vector3 _rotation = Vector3.zero;
  private bool _isRotating;
  private Quaternion original;
  
  
  #endregion
  void start(){
      original = transform.rotation;
  }
  
  void Update()
  {
      if(_isRotating)
      {
          // offset
          _mouseOffset = (Input.mousePosition - _mouseReference); // apply rotation
          _rotation.y = -(_mouseOffset.x + _mouseOffset.y) * _sensitivity; // rotate
          gameObject.transform.Rotate(_rotation); // store new mouse position
          _mouseReference = Input.mousePosition;
      }
  
  }
  
  public void OnMouseDown()
  {
      // rotating flag
      _isRotating = true;
  
      // store mouse position
      _mouseReference = Input.mousePosition;
  }
  
  public void OnMouseUp()
  {
      // rotating flag
      _isRotating = false;
      transform.rotation = original;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>"im trying to rotate a 3d model of a sofa and return to its starting rotation.but if i used this code " <strong>whenever if i stopped touching the sofa , it turns to **backside</strong> of sofa"**
   i want it to return to initial rotation.<a href="https://i.stack.imgur.com/M9pE2.png" rel="nofollow noreferrer">u can see initally this is how the sofa looks like and if i stopped touching it returns to its backside of sofa. i want it to return to its front side again if i stopped rotation</a></p>