# limiting the rotation of turret with mouse position in 2d

I am just a beginner and learning unity which i am developing small things to understand the concepts.
I am having a turret mounted at rectangle shape, where that turret is rotated by mouse positions.
But turret is rotating even when mouse mouse is behind it. How to rotate the turret 90 degree left and 90 degree right. But it could not move below even when mouse position moves.
Here is the image of what i am trying to achieve.

Here is the code goes for the turret object.

``````void Update ()
{
Vector3 mouse_pos = Input.mousePosition;
Vector3 player_pos = Camera.main.WorldToScreenPoint(this.transform.position);

mouse_pos.x = mouse_pos.x - player_pos.x;
mouse_pos.y = mouse_pos.y - player_pos.y;

float angle = Mathf.Atan2 (mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
Debug.Log (angle);

//if(angle )

this.transform.rotation = Quaternion.Euler (new Vector3(0, 0, angle));
}
``````

You can try
this.transform.rotation = Quaternion.Euler (new Vector3(0, 0, Math.Min( Math.Max( angle,0),180)));

Or

this.transform.rotation = Quaternion.Euler (new Vector3(0, 0, Math.Min( Math.Max( angle,-180),0)));