Infinite rotation

Hi. For smooth object rotation to some point I use coroutines with while loop and simple check, like:

IEnumerator ChangeModRotCoroutine(Quaternion lookDirection)
{
    while(transform.rotation != lookDirection)
    {
        Debug.Log(transform.rotation.eulerAngles + "    " + lookDirection.eulerAngles);
        transform.rotation = Quaternion.Lerp(transform.rotation, lookDirection, changeModRotSpeed);
        yield return new WaitForEndOfFrame();
    }
}

But sometimes this don’t work as I want - while loop becomes infinite and blockіs further rotations of object, because (transform.rotation != lookDirection) returns true, even when rotation is equal. Using Quaternion.Angle seems no helpfull.

When lerping, you get the result of “moving” value a closer to value b by amount t. Unless t = 1, you will technically never get value b as a result. If you do, it’s because of the underlying floats’ finite capability for precision.
So checking whether these two rotations are equal should rarely give you a decent result. The solution, despite what you’re saying, is using Quaternion.Angle instead and exiting the loop when a sensibly chosen threshold angle is passed.