Examining objects in game by rotating them

I’m trying to implement a mechanic that allows a player to rotate an object by dragging the mouse on screen. However, being a rather… slow programmer, I don’t know where to start with this.

I sort of have the idea that I should track the mouse’s X and Y positions while the left mouse button is held down, but I don’t know how to convert the X and Y coordinates to an object’s rotation.

If anyone was wondering what exactly I’m talking about, I trying to let players examine objects close up the way Skyrim allows players to examine items.

Edit: I forgot to mention that I’m trying to program this in C#. While JS is helpful, it just doesn’t cut it.

Hi, try to see touchphaase.moved example… in unity scripting reference ,its like below

var speed : float = 0.1;
function Update () {
if (Input.touchCount > 0
Input.GetTouch(0).phase == TouchPhase.Moved) {

var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;

transform.Rotate (0,-touchDeltaPosition.x * speedTime.deltaTime,
-touchDeltaPosition.y * speed
Time.deltaTime);

}

}

That’s not helping at all. I tried implementing the code, altering it so it can be integrated and nothing. I looked up the script reference and I can’t seem to get anything working. Anyone else?

here, this should give you the right direction

using UnityEngine;
using System.Collections;

public class RotateObject : MonoBehaviour {

	public float speed = 100f;
	
	private Transform _tr = null;
	private Vector2 _lastMousePosition = Vector2.zero;
	
	// Use this for initialization
	void Start () {
		_tr = gameObject.transform;
	}
	
	// Update is called once per frame
	void Update () {
		
		Vector2 _currentMousePosition = (Vector2)Input.mousePosition;
		Vector2 mouseDelta = _currentMousePosition - _lastMousePosition;
		mouseDelta *= speed * Time.deltaTime;
		
		_lastMousePosition = _currentMousePosition;
		
		if(Input.GetMouseButton(0)){
			_tr.Rotate(0f, mouseDelta.x * -1f, 0f, Space.World);
		}
	}
}