I modified the code based on the last post by Mike Miller in this forum.
http://answers.unity3d.com/questions/14919/rotate-point-a-on-sphere-to-point-b-on-sphere
I tried to have the object spin only in the Z axis so I set rot.x and rot.y to zero after the Quaternion output. I also set sumz += rot.z to keep track of the value summed in the rotation for the Z axis of the Quaternion(also to get the boundary at 300 and 0). For some reason after a few rotation the object isn't cenetered at 0, the sum value is also incorrect. Is it wrong to use the sum value of the Quaternion or should I try transform.rotate instead?
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
bool hasGrabbedPoint = false;
bool hitobj = false;
bool hitobjtest = false;
Vector3 grabbedPoint;
void Update () {
if (Input.GetMouseButton(0))
{
hitobjtest=Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition));
if(!hasGrabbedPoint)
{
if(hitobjtest)
{
hasGrabbedPoint = true;
grabbedPoint = getTouchedPoint();
}
else
hasGrabbedPoint = false;
}
else
{
if(hitobjtest)
{
Vector3 targetPoint = getTouchedPoint();
Quaternion rot = Quaternion.FromToRotation (grabbedPoint, targetPoint);
rot.x = 0;
rot.y = 0;
Po.sumz += rot.z;
if(Po.sumz > 300)
{
rot.z = 0;
Po.sumz = 300;
}
if(Po.sumz < 0)
{
rot.z = 0;
Po.sumz = 0;
}
transform.localRotation *= rot;
}
else
hasGrabbedPoint = false;
}
}
else
hasGrabbedPoint = false;
}
Vector3 getTouchedPoint()
{
RaycastHit hit;
hitobj=Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit);
return transform.InverseTransformPoint(hit.point);
}
}