Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PathManager : MonoBehaviour
  6. {
  7. public static float RY = 0;
  8. public List<Path> paths;
  9. public int maxPaths = 40;
  10. public GameObject pathPrefab;
  11. public GameObject pathPrefab2;
  12. public GameObject pathPrefab3;
  13. public Vector3 nextPosition;
  14. public int sameTurnsL = 0;
  15. public int sameTurnsR = 0;
  16. public bool lastStraight = false;
  17. // Start is called before the first frame update
  18. void Start()
  19. {
  20.  
  21.  
  22. for (int i = 0; i < maxPaths; i ++)
  23. {
  24. if (RY == -360f)
  25. {
  26. RY = 0f;
  27. }
  28. var chooseFloat = Random.Range(0f,1f);//testing
  29. //GameObject go = null;
  30. if (chooseFloat <= 0.3 || i == 0)
  31. {
  32. GameObject go = Instantiate<GameObject>(pathPrefab);
  33. Path path = go.GetComponent<Path>();
  34. if (i == 0)
  35. {
  36. nextPosition = path.attachPoint.transform.position;
  37. }
  38. else
  39. {
  40. //var nextTransform = path.attachPoint;
  41. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  42. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  43. nextPosition = path.attachPoint.transform.position;
  44.  
  45. }
  46. lastStraight = true;
  47. }
  48. else if (chooseFloat > 0.3 && chooseFloat <= 0.7)
  49. {
  50. if (sameTurnsL < 2)
  51. {
  52. GameObject go = Instantiate<GameObject>(pathPrefab2);
  53. Path path = go.GetComponent<Path>();
  54. if (i == 0)
  55. {
  56. nextPosition = path.attachPoint.transform.position;
  57. RY -= 90;
  58. }
  59. else
  60. {
  61. //var nextTransform = path.attachPoint;
  62.  
  63.  
  64. //fix all the offsets------------
  65. if (RY == 0)
  66. nextPosition.z -= 0.5f;
  67. else if (RY == 90 || RY == -270)
  68. nextPosition.x -= .5f;
  69. else if (RY == 180 || RY == -180)
  70. nextPosition.z += 0.5f;
  71. else if (RY == -90)
  72. nextPosition.x += .5f;
  73. //that was annoying :)-------------
  74.  
  75.  
  76.  
  77. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  78. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  79. RY -= 90;
  80. nextPosition = path.attachPoint.transform.position;
  81.  
  82. }
  83. sameTurnsL += 1;
  84. lastStraight = false;
  85. if (sameTurnsR > 0)
  86. {
  87. sameTurnsR -= 1;
  88. }
  89. }
  90. else
  91. {
  92.  
  93. GameObject go = Instantiate<GameObject>(pathPrefab);
  94. Path path = go.GetComponent<Path>();
  95. if (i == 0)
  96. {
  97. nextPosition = path.attachPoint.transform.position;
  98. }
  99. else
  100. {
  101. //var nextTransform = path.attachPoint;
  102. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  103. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  104. nextPosition = path.attachPoint.transform.position;
  105.  
  106. }
  107. lastStraight = true;
  108. sameTurnsL -= 1;
  109. }
  110.  
  111. }
  112. else
  113. {
  114. if (sameTurnsR < 2)
  115. {
  116. GameObject go = Instantiate<GameObject>(pathPrefab3);
  117. Path path = go.GetComponent<Path>();
  118. if (i == 0)
  119. {
  120. nextPosition = path.attachPoint.transform.position;
  121. RY += 90;
  122. }
  123. else
  124. {
  125.  
  126. //var nextTransform = path.attachPoint;
  127. //fix all the offsets------------
  128. if ((RY) == 0)
  129. nextPosition.z += .5f;
  130. else if ((RY) == 90 || RY == -270)
  131. nextPosition.x += .5f;
  132. else if ((RY) == 180 || RY == -180)
  133. nextPosition.z -= .5f;
  134. else if (RY == -90)
  135. nextPosition.x -= .5f;
  136. //that sucked :)----------------
  137.  
  138. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  139. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  140. RY += 90;
  141.  
  142. nextPosition = path.attachPoint.transform.position;
  143.  
  144. }
  145. sameTurnsR += 1;
  146. if (sameTurnsL > 0)
  147. {
  148. sameTurnsL -= 1;
  149. }
  150. lastStraight = false;
  151. }
  152. else
  153. {
  154. GameObject go = Instantiate<GameObject>(pathPrefab);
  155. Path path = go.GetComponent<Path>();
  156. if (i == 0)
  157. {
  158. nextPosition = path.attachPoint.transform.position;
  159. }
  160. else
  161. {
  162. //var nextTransform = path.attachPoint;
  163. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  164. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  165. nextPosition = path.attachPoint.transform.position;
  166.  
  167. }
  168. lastStraight = true;
  169. sameTurnsR -= 1;
  170. }
  171. }
  172.  
  173.  
  174.  
  175.  
  176. }
  177. }
  178.  
  179. // Update is called once per frame
  180. void Update()
  181. {
  182.  
  183. }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement