Advertisement
duck

Camera mouselook / orbit

Nov 10th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Player : MonoBehaviour
  6. {
  7.  
  8.     float rotationSpeed = 5;
  9.     float rotationX = 0F;
  10.     float rotationY = 0F;
  11.  
  12.     void Update()
  13.     {
  14.         rotationX += Input.GetAxis("Mouse X") * rotationSpeed;
  15.         rotationY += Input.GetAxis("Mouse Y") * rotationSpeed;
  16.     rotationY = Mathf.Clamp(rotationY,-90,90);
  17.        
  18.         xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
  19.         yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);
  20.  
  21.         transform.localRotation = xQuaternion * yQuaternion;
  22.  
  23.     }
  24. }
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement