Skip to content

Instantly share code, notes, and snippets.

@buijldert
Last active August 27, 2018 14:49
Show Gist options
  • Save buijldert/91d6957c6e15b63f1ab8c25805fe9242 to your computer and use it in GitHub Desktop.
Save buijldert/91d6957c6e15b63f1ab8c25805fe9242 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class MouseRotateTransformY : MonoBehaviour
{
private float sensitivity;
private Vector3 mousePos;
private Vector3 mouseOffset;
private Vector3 rotation;
private void Start ()
{
sensitivity = 0.4f;
rotation = Vector3.zero;
}
private void OnMouseDown()
{
mousePos = Input.mousePosition;
}
private void OnMouseDrag()
{
mouseOffset = Input.mousePosition - mousePos;
rotation.y = -(mouseOffset.x + mouseOffset.y) * sensitivity;
transform.Rotate(rotation);
mousePos = Input.mousePosition;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment