I think I have found an answer to my problem. I was having the same problem as the person here: Limit local rotation - Questions & Answers - Unity Discussions
The problem is that is in JavaScript. Can someone convert it to C# and tell me how to integrate it into my script?
My script:
using UnityEngine;
using System.Collections;
public class CameraRotation : MonoBehaviour {
float FinalRotation;
public float GunDepression = -10.0f;
public float GunElevation = 25.0f;
public float XSpeed = 0.1f;
public float YSpeed = 0.1f;
public float Sensitivity = 100f;
float LockPos = 0;
void Update () {
float XSpeed = Input.GetAxis ("Mouse X") * Sensitivity * Time.deltaTime;
float YSpeed = Input.GetAxis ("Mouse Y") * Sensitivity * Time.deltaTime;
transform.Rotate (YSpeed, XSpeed, 0); //yes, those axis are correct.
FinalRotation = transform.rotation.x;
transform.localEulerAngles = new Vector3(Mathf.Clamp(transform.rotation.x, GunDepression, GunElevation), transform.localEulerAngles.y, LockPos);
}
}