Add max Angle to rotation.

Hi, how can i add the max rotation angle to this script?

#pragma strict

var amount = 5.0;

	
	
	
function Awake ()
{
 
}


	
function FixedUpdate()
{
   if (Input.GetKey(KeyCode.A)) {
      rigidbody.AddForce(transform.right * amount);
   }
   else if (Input.GetKey(KeyCode.D)) {
      rigidbody.AddForce(-transform.right * amount);
   }
   else if (Input.GetKey(KeyCode.S)) {
      rigidbody.velocity = rigidbody.velocity * 0.9;
   }
   
   
   
}

Hi
Inorder for you to restrict an objects rotation you need to know some basics about Vectors
and how Unity sees it

and is the object rotates manually from this script or another script ?

here is an simple script that restricts the object rotation on its Z axis with respect to its forward vector at start

public var MaxAngle:float = 180f;


private var CurrentAngle:float =0;

Vector3 ForwardVector;
Quaternion rotation;

function Start()
{
 ForwardVector = transform.forward;
}

function Update()

{

}

function LateUpdate()
{


  CurrentAngle = Vector3.Angle(ForwardVector,transform.forward);
    
     if(CurrentAngle <= MaxAnlge)
       rotation = transform.rotation; //update the changs only if angle is less than max
    
      transform.rotation.x = rotation.x;    // set rotation on x axis (which maske the object rotate forward)      
    
     
    }

**Note : this is an simple script that restricts the angle on zaxis only if you want it on other axis then you have to write another code or just write the same code for different axis as well .If want any help please ask **