#pragma strict
//Speed of rotation degrees per second
var Speed : float = 50.0f;
//Rotation limit
var MaxAngle : float = 30.0f;
private var XCurRotation : float = 0;
private var ZCurRotation : float = 0;
function Update () {
var XRot : float = 0;
var ZRot : float = 0;
if(Input.GetKey(KeyCode.W))
XRot : Time.deltaTime * Speed;
if(Input.GetKey(KeyCode.S))
XRot : Time.deltaTime * -Speed;
if(Input.GetKey(KeyCode.A))
ZRot : Time.deltaTime * Speed;
if(Input.GetKey(KeyCode.D))
ZRot : Time.deltaTime * -Speed;
if ((XCurRotation+XRot < -MaxAngle) || (XCurRotation+XRot > MaxAngle))
return;
if ((ZCurRotation+ZRot < -MaxAngle) || (ZCurRotation+ZRot > MaxAngle))
return;
XCurRotation += XRot;
ZCurRotation += ZRot;
transform.Rotate (Vector3.right * ZRot);
transform.Rotate (Vector3.forward * XRot, Space.World);
}