rotation issue

Hello,

I am developing tap like game.

OnMouseDown I increment eulersAngle by 120.

when it reaches to 360,it continuously keeps rotating, means not stopping on 360.

here is my code :

void Update ()
{
    transform.eulerAngles = Vector3.RotateTowards (transform.eulerAngles, euler, 20f, 20f);
}


void OnMouseDown ()
{
    DoRotation ();
}

private void DoRotation ()
{				
	euler = transform.eulerAngles;
	euler.z += 120f;
}

@bhartu
you can use transform.Rotate to rotate gameobject. according to doc eulerAngles
“Only use this variable to read and set the angles to absolute values. Don’t increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate instead.”
so use

 private void DoRotation ()
 {                
     transform.Rotate(new Vector3(0,0,120f));
 }

You have not added the rotation count limit. In your script, euler.z +=120f;

Try something like this (Pseudo Code, not tested! Probably should give you some idea)

float  minRot = 0;

float maxRot = 360;

transform.rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, Mathf.Clamp, transform.rotation.eulerAngles.y, (transform.rotation.eulerAngles.z, minRot, maxRot));