Trying To use transform.Rotate for only 180, on a pivot point

I have a sprite which i want to only rotate 180 degrees from its central pivot, the code below is what i have so far, is there any way that i can stop the object from rotating once it gets from 0 degrees to 180 degrees and vice versa… i am new to all this so please keep it simple.
Hope someone can help.

  function Update () 
    {
       if(Input.GetKey(KeyCode.RightArrow)) 
        {
            // Clockwise
            transform.Rotate(0,0, -1.5); // --> Instead of "transform.Rotate(-1.0f, 0.0f, 0.0f);"
        }
    
        if(Input.GetKey(KeyCode.LeftArrow)) 
        {
            // Counter-clockwise
            transform.Rotate(0, 0, 1.5); // --> Instead of transform.Rotate(1.0f, 0.0f, 0.0f);
    
        }
    }

Rotations and clamping rotations can be tricky things. Assuming your object starts with zero rotation and you are only rotating it around the ‘z’ axis, you can do something like:

#pragma strict

private var angle : float = 0.0;
var speed : float = 90.0;

function Update () 
{
	if(Input.GetKey(KeyCode.RightArrow)) 
	{
	    angle -= speed * Time.deltaTime;
	    if (angle < -180.0) angle = -180.0;
	    transform.eulerAngles = Vector3(0,0, angle); 
	}

	if(Input.GetKey(KeyCode.LeftArrow)) 
	{
	    angle += speed * Time.deltaTime;
	    if (angle > 180.0) angle = 180.0;
	    transform.eulerAngles = Vector3(0, 0, angle); 
	}
}