Return to the point of rotation?

Hi,

I’m trying to spin one object with the cursor and when the spinning is finished, the object wait for 2 seconds and then return to the point or rotation.

The rotation is working but, the return to the point of rotation is not working.

Please take a look to my script any advice is welcome

Thanks in advance.

   var rotationSpeed = 20; // rotation speed
   var rotationStart = 0.0; // rotation on start 
      
 
    function Awake () {
        transform.Rotate(rotationStart,0,0);
    }
     
 
    function Update (){
        
        if (Input.GetButton("Fire1")){
        transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
            
        if (Input.GetButtonUp ("Fire1")) {
        yield WaitForSeconds (2.0);
        transform.Rotate(rotationStart,0,0);
    	
    	}    
      }
    }

Try:

transform.rotation = Quaternion.Euler(rotationStart,0,0);

Your code complete:

#pragma strict

var rotationSpeed = 20; // rotation speed
var rotationStart = 0.0; // rotation on start 

function Awake () {
	transform.Rotate(rotationStart,0,0);
}

function Update (){

    if (Input.GetButton("Fire1")){
	    transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
    }
    if (Input.GetButtonUp ("Fire1")) {
    	StartCoroutine("Return",2);
    }
}

function Return(){
    yield WaitForSeconds (2.0);
    transform.rotation =  Quaternion.Euler(rotationStart,0,0);
}

Hi Lovrenc,

Thanks for your help, I made the change to the script but is not working, here it is my Updated script.

any advice?

Thanks again

   var rotationSpeed = 20; // rotation speed
   var rotationStart = 0.0; // rotation on start 
      
 
   function Awake () {
   transform.Rotate(rotationStart,0,0);
   }
     
 
   function Update (){
        
   if (Input.GetButton("Fire1")){
   transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
            
   }
   }
     
   function Return(){
       
   if (Input.GetButtonUp ("Fire1")) {
   yield WaitForSeconds (2.0);
   transform.rotation = Quaternion.euler(rotationStart,0,0);
   }
   }