private IEnumerator RotateFace(RubiksFace faceToRotate, FaceRotation direction, GameObject faceGO, float duration = 1.0f, RotationCallback callback = null) { Quaternion from = faceGO.transform.localRotation; Quaternion to = faceGO.transform.localRotation; to *= Quaternion.Euler(GetMultiplierForRotation(faceToRotate, direction) * GetAxisForFace(faceToRotate) * NINETY_DEGREES); float elapsed = 0.0f; while (elapsed < duration) { faceGO.transform.rotation = Quaternion.Slerp(from, to, elapsed / duration); elapsed += Time.deltaTime; yield return(null); } faceGO.transform.rotation = to; ResetRubiksFaceParents(); callback?.Invoke(GetFaceColor(faceToRotate), direction); RubiksCubeRotation.SetRotationState(RubiksCubeRotation.RotationState.IDLE); }
public void Rotate(RubiksFace faceToRotate, FaceRotation direction, GameObject faceGO, float rotationDuration, RotationCallback callback = null) { RubiksCubeRotation.SetRotationState(RubiksCubeRotation.RotationState.ROTATING); SetRubiksFaceParents(faceToRotate, faceGO); StartCoroutine(RotateFace(faceToRotate, direction, faceGO, rotationDuration, callback)); }