public void Rotate(float aroundX, float aroundY, float aroundZ, bool tween = true) { if (tween) { LevelManagerScript.CubeIsMoving(); StartCoroutine(AnimRotate(aroundX, aroundY, aroundZ)); } else { this.transform.Rotate(new Vector3(aroundX, aroundY, aroundZ), Space.World); } }
private IEnumerator AnimRotate(float aroundX, float aroundY, float aroundZ) { var goal = 0f; var deltaX = GetDelta(aroundX, ref goal); var deltaY = GetDelta(aroundY, ref goal); var deltaZ = GetDelta(aroundZ, ref goal); var increment = Mathf.Max(Mathf.Abs(deltaX), Mathf.Abs(deltaY), Mathf.Abs(deltaZ)); goal = Mathf.Abs(goal); var sum = 0f; while (sum < goal) { this.transform.Rotate(new Vector3(deltaX, deltaY, deltaZ), Space.World); yield return(new WaitForEndOfFrame()); sum += increment; } LevelManagerScript.CubeStoppedMoving(); }