private IEnumerator FlipX ( float rotation, float rotationSpeed ) { flipping = true; Vector3 startRotation = transform.localEulerAngles; if ( rotation > 0 ) { float newAngle = startRotation.x + rotation; while ( startRotation.x < newAngle ) { if ( startRotation.x + 50 > newAngle ) { Debug.Log( "Almost done" ); } startRotation.x = Mathf.MoveTowards( startRotation.x, newAngle, rotationSpeed * Time.deltaTime ); transform.localEulerAngles = startRotation; yield return new WaitForSeconds( 0.009f ); } stunttype = StuntType.ForwardFlip; } else { float newAngle = startRotation.x + rotation; while ( startRotation.x > newAngle ) { if ( startRotation.x - 50 < newAngle ) { Debug.Log( "Almost done" ); } startRotation.x = Mathf.MoveTowards( startRotation.x, newAngle, rotationSpeed * Time.deltaTime ); transform.localEulerAngles = startRotation; yield return new WaitForSeconds( 0.009f ); } stunttype = StuntType.BackwardFlip; } flipping = false; DisplayStunt( 4 ); }
private IEnumerator FlipZ ( int rotation, float rotationSpeed ) { flipping = true; Vector3 startRotation = transform.localEulerAngles; if ( rotation > 0 ) { float newAngle = startRotation.z + rotation; while ( startRotation.z < newAngle ) { if ( startRotation.z + 50 > newAngle ) { Debug.Log( "Almost done" ); } startRotation.z = Mathf.MoveTowards( startRotation.z, newAngle, rotationSpeed * Time.deltaTime ); transform.localEulerAngles = startRotation; yield return new WaitForSeconds( 0.009f ); } stunttype = StuntType.LeftRoll; } else { float newAngle = startRotation.z + rotation; while ( startRotation.z > newAngle ) { if ( startRotation.z - 50 < newAngle ) { Debug.Log( "Almost done" ); } startRotation.z = Mathf.MoveTowards( startRotation.z, newAngle, rotationSpeed * Time.deltaTime ); transform.localEulerAngles = startRotation; yield return new WaitForSeconds( 0.009f ); } stunttype = StuntType.RightRoll; } flipping = false; DisplayStunt( 2 ); }