Created
September 11, 2014 20:34
-
-
Save olegchir/7ba60e3df8ffd1ec58f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class MouseLookScript : MonoBehaviour { | |
[HideInInspector] | |
public float xRotation; | |
[HideInInspector] | |
public float yRotation; | |
public float lookSensitivity = 5; | |
[HideInInspector] | |
public float currXRotation; | |
[HideInInspector] | |
public float currYRotation; | |
[HideInInspector] | |
public float xRotationVelocity; | |
[HideInInspector] | |
public float yRotationVelocity; | |
public float smoothDampTime = 0.1f; | |
// Update is called once per frame | |
void Update () { | |
xRotation -= Input.GetAxis ("Mouse Y") * lookSensitivity; | |
yRotation += Input.GetAxis ("Mouse X") * lookSensitivity; | |
xRotation = Mathf.Clamp(xRotation, -90, 90); | |
currXRotation = Mathf.SmoothDamp(currXRotation, xRotation, ref xRotationVelocity, smoothDampTime); | |
currYRotation = Mathf.SmoothDamp(currYRotation, yRotation, ref yRotationVelocity, smoothDampTime); | |
transform.rotation = Quaternion.Euler(currXRotation, currYRotation, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment