
Untitled
By: a guest on
May 12th, 2012 | syntax:
None | size: 2.44 KB | hits: 9 | expires: Never
/// <summary>
/// FPSMouseLook.cs
/// Niels Wouters
/// 11 May 2012
/// </summary>
using UnityEngine;
using System.Collections;
public class FPSMouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 } // Enum voor het instellen van de axes (MouseXAndY, MouseX, MouseY)
public RotationAxes axes = RotationAxes.MouseXAndY; // Een variabele axes voor de enum en zet de default als MouseXAndY
//
public float sensitivityX = 400f; // De gevoeligheid voor de X richting
public float sensitivityY = 400f; // De gevoeligheid voor de Y richting
public float minimumY = -60f; // Minimum draaiing van de Y richting
public float maximumY = 60f; // Maximum draaiing van de Y richting
float rotationY = 0f; // De variabele rotationY voor het bijhouden van de Y rotatie
float rotationX = 0f; // De variabele rotationX voor het bijhouden van de X rotatie
void Update ()
{
if (axes == RotationAxes.MouseXAndY) // Als je beide richtingen wilt bewegen
{
rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime; // De X rotatie berekenen en de gevoeligheid toepassen
rotationY += Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime; // De Y rotatie berekenen en de gevoeligheid toepassen
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); // De Y rotatie binnen de minimum en maximum houden
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0); // De rotatie toepassen op het object
}
else if (axes == RotationAxes.MouseX) // Als je enkel de X richting wilt bewegen
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime, 0); // De X rotatie berekenen en de gevoeligheid toepassen en meteen toepassen op het object
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime; // De Y rotatie berekenen en de gevoeligheid toepassen
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); // De Y rotatie binnen de minimum en maximum houden
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0); // De y rotatie toepassen op het object
}
}
}