- Home /
 
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 ();  
Answer by DaveA · Feb 17, 2011 at 05:18 PM
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 (); 
 
              Your answer
 
             Follow this Question
Related Questions
GUI Group Clipping on Rotation 0 Answers
Constant Rotation with GUI.RotateAroundPivot 1 Answer
Rotate Object Via GUI 2 Answers
ScreentoWorld point help- rotation 1 Answer
Rotating, Scrolling textures act in GUI? 0 Answers