eastbayeff

Untitled

Nov 20th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class JumpRotate : MonoBehaviour
  6. {
  7.     bool isRotating = false;
  8.  
  9.     void Update()
  10.     {
  11.         if (Input.GetKeyDown(KeyCode.Space))
  12.         {
  13.             // this is where your jump code would be
  14.             if (!isRotating)
  15.             {
  16.                 StartCoroutine(Rotate90Degrees());
  17.             }
  18.         }
  19.     }
  20.  
  21.     IEnumerator Rotate90Degrees()
  22.     {
  23.         isRotating = true;
  24.         var timer = 0f;
  25.         var duration = 1f;
  26.         var startingRotation = transform.rotation;
  27.         var targetRotation = transform.rotation * Quaternion.Euler(0, 0, -90);
  28.  
  29.         while (timer < duration)
  30.         {
  31.             transform.rotation = Quaternion.Lerp(startingRotation, targetRotation, timer / duration);
  32.             timer += Time.deltaTime;
  33.             yield return null;
  34.         }
  35.  
  36.         transform.rotation = targetRotation;
  37.         isRotating = false;
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment