Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class RotateRandom : MonoBehaviour
  6. {
  7. bool noTarget = true;
  8. Quaternion qTo;
  9. float rotateSpeed = 3.0f;
  10. float timer = 0.0f;
  11.  
  12. private void Start()
  13. {
  14. qTo = Quaternion.Euler(new Vector3(0.0f, Random.Range(135.0f, 225.0f), 0.0f));
  15. }
  16.  
  17. private void Update()
  18. {
  19. timer += Time.deltaTime;
  20.  
  21. if (noTarget == true)
  22. {
  23. if (timer > 2)
  24. {
  25. qTo = Quaternion.Euler(new Vector3(0.0f, Random.Range(135.0f, 225.0f), 0.0f));
  26.  
  27. timer = 0.0f;
  28. }
  29. transform.rotation = Quaternion.Slerp(transform.rotation, qTo, Time.deltaTime * rotateSpeed);
  30. }
  31. }
  32. }
  33.  
  34. using System.Collections;
  35. using System.Collections.Generic;
  36. using UnityEngine;
  37.  
  38. public class RotateRandom : MonoBehaviour
  39. {
  40. bool noTarget = true;
  41. Quaternion qTo;
  42. float speed = 1.25f;
  43. float rotateSpeed = 3.0f;
  44. float timer = 0.0f;
  45. int counter = 0;
  46.  
  47. private void Start()
  48. {
  49. qTo = Quaternion.Euler(new Vector3(0.0f, Random.Range(90.0f, 270.0f), 0.0f));
  50. }
  51.  
  52. private void Update()
  53. {
  54.  
  55. timer += Time.deltaTime;
  56.  
  57. if (noTarget == true)
  58. {
  59. if (timer > 2)
  60. {
  61. var rand = Random.Range(90.0f, 270.0f);
  62. counter += 1;
  63. if (rand >= 90 && rand <= 180)
  64. {
  65. if(counter == 2)
  66. {
  67. rand = Random.Range(180.0f, 270.0f);
  68. counter = 0;
  69. }
  70. }
  71.  
  72. if (rand >= 270 && rand >= 180)
  73. {
  74. if (counter == 2)
  75. {
  76. rand = Random.Range(90.0f, 180.0f);
  77. }
  78. counter = 0;
  79. }
  80.  
  81. qTo = Quaternion.Euler(new Vector3(0.0f, rand, 0.0f));
  82. timer = 0.0f;
  83. }
  84. transform.rotation = Quaternion.Slerp(transform.rotation, qTo, Time.deltaTime * rotateSpeed);
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement