Hey !

I’m having a annoying issue with Mathf.Clamp. The issue is that I can’t clamp the rotation between 330 and 30. This script below is attached to a gun held by a character. I want to basicly limit the rotation between 330 and 30. I’ve tried limiting the angle in between 30 and 330 but then the gun shoots backwards.

I hope you guys could help me out, and sorry about my shitty explanation.

```
void Update ()
{
Vector3 mousePos = Input.mousePosition;
mousePos.z = -(transform.position.x - Camera.main.transform.position.x);
Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position);
mousePos.x = mousePos.x - objectPos.x;
mousePos.y = mousePos.y - objectPos.y;
float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
angle += 180f; //So the gun is directed towards the mouse
/*if(angle < 330)
{
transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
}*/
//angle = Mathf.Clamp(angle, 330, 30);
//angle = Mathf.Min(30);
//angle = Mathf.Max (330);
angle = ClampAngle (angle, 330, 30);
//angle = Mathf.Clamp (angle, -100, 100);
//transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
Debug.Log (angle);
transform.eulerAngles = new Vector3(0, 0, angle);
}
public static float ClampAngle (float angle, float min, float max) {
if (angle < 30.0f)
angle += 30.0f;
if (angle > 330.0f)
angle -= 330.0f;
//Debug.Log (angle);
return Mathf.Clamp (angle, min, max);
}
```