The equality operator for quaternions accepts nearly equal rotations: Unity verifies if the dot product of the two quaternions is close enough to 1, what should mean they are almost the same. But this “close enough to 1” is fixed by Unity; if you want to control the error margin, do the dot product yourself:
if (Quaternion.Dot(targetRot, transform.rotation) > 0.99){
// rotation is very close to targetRot
}
But you can be more specific yet: use Quaternion.Angle, thus you can specify an error margin in degrees, which’s way more intuitive:
if (Quaternion.Angle(targetRot, transform.rotation) <= 2){
// rotation is at 2 degrees or less from targetRot
}