EscapeTheRoom/Assets/Scripts/Test/CameraRotation.cs
2015-11-08 07:46:16 -05:00

44 lines
932 B
C#

using UnityEngine;
using System.Collections;
public class CameraRotation : MonoBehaviour
{
public float AngularSpeed = 10;
public float MaxYAngle = 290;
public float MinYAngle = 70;
private Transform _transform;
void Awake()
{
_transform = GetComponent<Transform>();
}
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
HandleRotationInput();
}
private void HandleRotationInput()
{
Vector3 rotation = _transform.localEulerAngles + new Vector3(-Input.GetAxis("Mouse Y"), 0f, 0f) * AngularSpeed;
if (rotation.x < MaxYAngle && rotation.x > 180)
{
rotation.x = MaxYAngle;
}
else if (rotation.x > MinYAngle && rotation.x < 180)
{
rotation.x = MinYAngle;
}
_transform.localEulerAngles = rotation;
}
}