Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Rotator : MonoBehaviour
  6. {
  7. public float Range = 90;
  8.  
  9. private void Start()
  10. {
  11. StartCoroutine(ScanRotateRange(Range));
  12. }
  13.  
  14. [ContextMenu("ForceScan")]
  15. private void ForceScan()
  16. {
  17. StartCoroutine(ScanRotateRange(Range));
  18. }
  19.  
  20. private IEnumerator ScanRotateRange(float range)
  21. {
  22. var rotationSpeed = 100f;
  23. var initialRotation = transform.rotation;
  24. var rightRotation = transform.rotation*Quaternion.AngleAxis(range/2, Vector3.up);
  25. var leftRotation = transform.rotation*Quaternion.AngleAxis(-range/2, Vector3.up);
  26.  
  27. while (transform.rotation != rightRotation)
  28. {
  29. transform.rotation = Quaternion.RotateTowards(transform.rotation, rightRotation,
  30. rotationSpeed * Time.deltaTime);
  31. yield return null;
  32. }
  33. while (transform.rotation != leftRotation)
  34. {
  35. transform.rotation = Quaternion.RotateTowards(transform.rotation, leftRotation,
  36. rotationSpeed * Time.deltaTime);
  37. yield return null;
  38. }
  39. while (transform.rotation != initialRotation)
  40. {
  41. transform.rotation = Quaternion.RotateTowards(transform.rotation, initialRotation,
  42. rotationSpeed * Time.deltaTime);
  43. yield return null;
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement