Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class JumpRotate : MonoBehaviour
- {
- bool isRotating = false;
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- // this is where your jump code would be
- if (!isRotating)
- {
- StartCoroutine(Rotate90Degrees());
- }
- }
- }
- IEnumerator Rotate90Degrees()
- {
- isRotating = true;
- var timer = 0f;
- var duration = 1f;
- var startingRotation = transform.rotation;
- var targetRotation = transform.rotation * Quaternion.Euler(0, 0, -90);
- while (timer < duration)
- {
- transform.rotation = Quaternion.Lerp(startingRotation, targetRotation, timer / duration);
- timer += Time.deltaTime;
- yield return null;
- }
- transform.rotation = targetRotation;
- isRotating = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment