Hi,
I’m trying to keep rotating an object 90 degrees then pause the rotation for a few seconds, I used eulerAngles but my script stops working when the eulerAngles goes from 350 degrees to 0.
Any ideas how to work around this?
Thank you
public class RotatePause : MonoBehaviour
{
// Rotation speed & axis
public int speed = 100;
public int dir = 1;
float lastRotation;
bool canRotate;
float yRotation = 0;
void Start()
{
lastRotation = transform.rotation.eulerAngles.y;
canRotate = true;
}
void Update()
{
if (canRotate)
{
yRotation += Time.deltaTime * speed;
transform.rotation = Quaternion.Euler(0, yRotation, 0);
if (transform.rotation.eulerAngles.y > lastRotation + 90 )
{
canRotate = false;
transform.eulerAngles = new Vector3(0, lastRotation + 90, 0);
StartCoroutine("PauseRotation");
lastRotation = transform.rotation.eulerAngles.y;
}
}
}
IEnumerator PauseRotation()
{
yield return new WaitForSeconds(2.5f);
canRotate = true;
}
}