# How to rotate object every half of rotation?

Im trying to pause the state of a rotating object every half of the rotation reach…

``````			if(!pause){
transform.Rotate(new Vector3(0,0,-1)* rotationspeed * Time.deltaTime);
pauseAngle = transform.rotation.eulerAngles.z;
}
if(pauseAngle <= 180 && timerPause > 0 ){
timerPause -= Time.deltaTime;
pause = true;

}
if(timerPause <= 0){
timerPause = 2;
pause = false;
}
``````

But I cant get the 2nd Pause of the next rotation. Can someone help?

hi,

``````  public float rotationspeed = 1;
public float timerPause = 1;
private bool pause;
private float angleRotatedsinceLastPause=0;
private float puaseAngle=180;

// Use this for initialization
void Start ()
{
}

// Update is called once per frame
void Update () {

if (!pause)
{
//rotate
Vector3 rotation = new Vector3(0, 0, -1)*rotationspeed*Time.deltaTime;
transform.Rotate(rotation);
angleRotatedsinceLastPause += Mathf.Abs(rotation.z);
//check if need to pause
if (angleRotatedsinceLastPause >= puaseAngle)
{
angleRotatedsinceLastPause = 0;
pause = true;
}

}
else
{
//count down to resume rotation
timerPause -= Time.deltaTime;
if (timerPause <= 0)
{
timerPause = 2;
pause = false;

}
}
}
``````

Try this.

``````public float rotationSpeed = 5f;
public float pauseTime = 2f;

private float nextPauseAngle = 180f;
private float rotated = 0f;
private bool pause = false;
private float timer = 0f;

void Update()
{
if(!pause)
{
float r = rotationSpeed * Time.deltaTime;
transform.Rotate(new Vector3(0,0,r));
rotated += Mathf.Abs(r);

if(rotated >= nextPauseAngle)
{
//pause rotation
timer = pauseTime;
pause = true;
nextPauseAngle += 180f;
}
}
else
{
timer -= Time.deltaTime;
if(timer <= 0)
{
//unpause
pause = false;
}
}
}
``````

Edit: Tested it and got this working.