Rotate the object to target position

Hi guys,

I have an object in my scene which receives certain values from another script, and these values are rotation angles for the object (rotation of object around Y axis). So, if a value 180 or 270 is passed, the object has to rotate 180 or 270 is the same direction.
I implemented this for requirement in the following way and this works to some extent as well:

IEnumerator RotateObject(Transform thisTransform, Vector3 endDegrees, float time){
		Quaternion startQuat = transform.rotation;
		Quaternion endQuat = transform.rotation * Quaternion.Euler (endDegrees);
		float rate = 1.0f / time;
		float t = 0.0f;
		while (t < 1.0) {
			t += Time.deltaTime * rate;
			transform.rotation = Quaternion.Slerp(startQuat, endQuat, t);
			yield return 0;
		}
	}

However, the problem here is that the Quaternion.Slerp actually takes the shortest path to the target rotation and hence my rotation slerping doesn’t always happen in the same direction. How do I rectify this here?
Thanks a lot for the help.

I would just lerp the currentDegreeAngle to the targetDegreeAngle and create the Quaternion by using Euler angles. Easiest method I know of

http://forum.unity3d.com/threads/96786-Force-to-rotate-180-passing-through-90º-not-90º

If I do that, will be I able to preserve the orientation that the object already has in the world? Say, currently, the object has a rotation of 50 degrees around Y axis and 50 degrees pitch around X-axis, the targetDegrees would be 410 degrees. Should I lerp between 50 and 410 and then assign the rotation as follows?

Quaternion initialRotation = transform.rotation;

void Update(){
   Mathf.Lerp(startDegrees, finalDegress, t); //where t is the fraction as calculated above
   transform.rotation = initialRotation * Quaternion.Euler(0,x,0); //where x is the lerp/interpolated value
}

I read somewhere that it’s better to treat eulerAngles are write-only - and if that’s the case, how would I get the startDegress how using in Mathf.Lerp?