How will we give from a fixed point to rotate operation by using mouse?

Hi All,

I want to make simple pendulum. I want like that
http://phet.colorado.edu/sims/pendulum-lab/pendulum-lab_en.html
in the above link by using mouse we can drag that pendulum a side.

But in mouse drag my code is this

using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshCollider))]
 
public class DragScript : MonoBehaviour 
{
 
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown()
{
    screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
    offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
		
{
    Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
}

by using this total position is changed.
but i want only rotation. i also tried

function Update () {
var mousePos = Input.mousePosition;
mousePos.z = 10.0f; //The distance from the camera to the player object
var lookPos : Vector3 = Camera.main.ScreenToWorldPoint(mousePos);
lookPos = lookPos - transform.position;
var angle : float = Mathf.Atan2(lookPos.y, lookPos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}

that is calculate mouse position and then rotate
at finally my question is how will i do that rotation by using mouse?

Thanks to all

One way is to build up the pendulum out of three game objects with a parent/child relationships. Start with a pivot game object. It can be a real game object, or an empty game object, but it is the point that everything will rotate around. Then make an arm, position it and make it a child of the pivot. Then make a bob/weight, position it and make it a child of the arm. The following source attaches to the bob/weight. You will need to drag the pivot onto the ‘pivot’ variable.

using UnityEngine;
using System.Collections;

public class DragRotate : MonoBehaviour {
	
	public Transform pivot;
	private float angle;
	private Vector3 v3Pivot;  // Pivot in screen space

	void Start () {
		v3Pivot = Camera.main.WorldToScreenPoint (pivot.position);
	 }
	
	void OnMouseDown() {
		Vector3 v3T = (Vector3)Input.mousePosition - v3Pivot;
		angle = Mathf.Atan2 (v3T.y, v3T.x) * Mathf.Rad2Deg;
	}
	
	void OnMouseDrag() {
		Vector3 v3T = (Vector3)Input.mousePosition - v3Pivot;
		float angleT  = Mathf.Atan2 (v3T.y, v3T.x)  * Mathf.Rad2Deg;
		float angleDiff = Mathf.DeltaAngle(angle, angleT);
		pivot.Rotate(new Vector3(0.0f, 0.0f, angleDiff));
		angle = angleT;
	}
}