# Limiting object rotation using GUI.Buttons?

I've searched for the answer to my problem, but can't find a solution.

What I want to do is rotate a GameObject only by using GUI.RepeatButtons but limit the rotation to certain angles left & right. Would appreciate any help.

This is my code:

var catapult : GameObject;

``````var catapult : GameObject;

//Arrows
GUI.BeginGroup (Rect ((Screen.width * 0.5) - 200, (Screen.height * 0.5) + 170,500,200));
if(GUI.RepeatButton (Rect (0,0,100,190), arrowImage, "Left Arrow"))
{
catapult.transform.Rotate (Vector3.down, rotateSpeed * Time.deltaTime);
}

if(GUI.RepeatButton (Rect (300, 0,100,190), arrowImage, "Right Arrow"))
{
catapult.transform.Rotate (Vector3.up, rotateSpeed * Time.deltaTime);
}

GUI.EndGroup ();

``````

Something like this

``````var catapult : GameObject;
var minAngle : float;
var maxAngle : float;
var curAngle : float = 0;

//Arrows
GUI.BeginGroup (Rect ((Screen.width * 0.5) - 200, (Screen.height * 0.5) + 170,500,200));
if(GUI.RepeatButton (Rect (0,0,100,190), arrowImage, "Left Arrow"))
{
curAngle = rotateSpeed * Time.deltaTime;
if (curAngle < minAngle)
curAngle = minAngle
catapult.transform.Rotate (Vector3.down, curAngle);
}

if(GUI.RepeatButton (Rect (300, 0,100,190), arrowImage, "Right Arrow"))
{
curAngle = rotateSpeed * Time.deltaTime;
if (curAngle > maxAngle)
curAngle = maxAngle
catapult.transform.Rotate (Vector3.down, curAngle);
}

GUI.EndGroup ();

``````