Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.45 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 GameObject player;
  9. public List<Path> paths;
  10. public int maxPaths = 5;
  11. public GameObject pathPrefab;
  12. public GameObject pathPrefab2;
  13. public GameObject pathPrefab3;
  14. public Vector3 nextPosition;
  15. public int sameTurnsL = 0;
  16. public int sameTurnsR = 0;
  17. public bool lastStraight = false;
  18. // Start is called before the first frame update
  19. void Start()
  20. {
  21. for (int i = 0; i < maxPaths; i ++)
  22. {
  23. if (RY == -360f)
  24. {
  25. RY = 0f;
  26. }
  27. var chooseFloat = Random.Range(0f,1f);//testing
  28. //GameObject go = null;
  29. if (chooseFloat <= 0.3 || i == 0)
  30. {
  31. GameObject go = Instantiate<GameObject>(pathPrefab);
  32. Path path = go.GetComponent<Path>();
  33. paths.Add(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. paths.Add(path);
  55. nextPosition = path.attachPoint.transform.position;
  56. RY -= 90;
  57. //var nextTransform = path.attachPoint;
  58.  
  59.  
  60. //fix all the offsets------------
  61. if (RY == 0)
  62. nextPosition.z -= 0.5f;
  63. else if (RY == 90 || RY == -270)
  64. nextPosition.x -= .5f;
  65. else if (RY == 180 || RY == -180)
  66. nextPosition.z += 0.5f;
  67. else if (RY == -90)
  68. nextPosition.x += .5f;
  69. //that was annoying :)-------------
  70.  
  71.  
  72.  
  73. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  74. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  75. RY -= 90;
  76. nextPosition = path.attachPoint.transform.position;
  77. sameTurnsL += 1;
  78. lastStraight = false;
  79. if (sameTurnsR > 0)
  80. {
  81. sameTurnsR -= 1;
  82. }
  83. }
  84. else
  85. {
  86.  
  87. GameObject go = Instantiate<GameObject>(pathPrefab);
  88. Path path = go.GetComponent<Path>();
  89. paths.Add(path);
  90. nextPosition = path.attachPoint.transform.position;
  91. //var nextTransform = path.attachPoint;
  92. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  93. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  94. nextPosition = path.attachPoint.transform.position;
  95. lastStraight = true;
  96. sameTurnsL -= 1;
  97. }
  98.  
  99. }
  100. else
  101. {
  102. if (sameTurnsR < 2)
  103. {
  104. GameObject go = Instantiate<GameObject>(pathPrefab3);
  105. Path path = go.GetComponent<Path>();
  106. paths.Add(path);
  107. nextPosition = path.attachPoint.transform.position;
  108. RY += 90;
  109. //var nextTransform = path.attachPoint;
  110. //fix all the offsets------------
  111. if ((RY) == 0)
  112. nextPosition.z += .5f;
  113. else if ((RY) == 90 || RY == -270)
  114. nextPosition.x += .5f;
  115. else if ((RY) == 180 || RY == -180)
  116. nextPosition.z -= .5f;
  117. else if (RY == -90)
  118. nextPosition.x -= .5f;
  119. //that sucked :)----------------
  120.  
  121. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  122. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  123. RY += 90;
  124.  
  125. nextPosition = path.attachPoint.transform.position;
  126. sameTurnsR += 1;
  127. if (sameTurnsL > 0)
  128. {
  129. sameTurnsL -= 1;
  130. }
  131. lastStraight = false;
  132. }
  133. else
  134. {
  135. GameObject go = Instantiate<GameObject>(pathPrefab);
  136. Path path = go.GetComponent<Path>();
  137. paths.Add(path);
  138. nextPosition = path.attachPoint.transform.position;
  139. //var nextTransform = path.attachPoint;
  140. go.transform.position = nextPosition;// - path.startPoint.transform.position;
  141. go.transform.rotation = Quaternion.Euler(0, RY, 0);
  142. nextPosition = path.attachPoint.transform.position;
  143. lastStraight = true;
  144. sameTurnsR -= 1;
  145. }
  146. }
  147.  
  148.  
  149.  
  150.  
  151. }
  152. }
  153. // Update is called once per frame
  154. //void Update()
  155. //{
  156. // if(Path.playerHere == true)
  157. // {
  158. // makeNewPath();
  159. // removeFirstPath();
  160. // }
  161. //}
  162.  
  163. //void makeNewPath()
  164. //{
  165. // var chooseFloat = Random.Range(0f, 1f);//testing
  166.  
  167. // if (chooseFloat > 0.3 && chooseFloat <= 0.7)
  168. // {
  169. // if (sameTurnsL < 2)
  170. // {
  171. // GameObject go = Instantiate<GameObject>(pathPrefab2);
  172. // Path path = go.GetComponent<Path>();
  173. // paths.Add(path);
  174. // nextPosition = path.attachPoint.transform.position;
  175. // RY -= 90;
  176. // //var nextTransform = path.attachPoint;
  177.  
  178.  
  179. // //fix all the offsets------------
  180. // if (RY == 0)
  181. // nextPosition.z -= 0.5f;
  182. // else if (RY == 90 || RY == -270)
  183. // nextPosition.x -= .5f;
  184. // else if (RY == 180 || RY == -180)
  185. // nextPosition.z += 0.5f;
  186. // else if (RY == -90)
  187. // nextPosition.x += .5f;
  188. // //that was annoying :)-------------
  189.  
  190.  
  191.  
  192. // go.transform.position = nextPosition;// - path.startPoint.transform.position;
  193. // go.transform.rotation = Quaternion.Euler(0, RY, 0);
  194. // RY -= 90;
  195. // nextPosition = path.attachPoint.transform.position;
  196. // sameTurnsL += 1;
  197. // lastStraight = false;
  198. // if (sameTurnsR > 0)
  199. // {
  200. // sameTurnsR -= 1;
  201. // }
  202. // }
  203. // else
  204. // {
  205.  
  206. // GameObject go = Instantiate<GameObject>(pathPrefab);
  207. // Path path = go.GetComponent<Path>();
  208. // paths.Add(path);
  209. // nextPosition = path.attachPoint.transform.position;
  210. // //var nextTransform = path.attachPoint;
  211. // go.transform.position = nextPosition;// - path.startPoint.transform.position;
  212. // go.transform.rotation = Quaternion.Euler(0, RY, 0);
  213. // nextPosition = path.attachPoint.transform.position;
  214. // lastStraight = true;
  215. // sameTurnsL -= 1;
  216. // }
  217.  
  218. // }
  219. // else
  220. // {
  221. // if (sameTurnsR < 2)
  222. // {
  223. // GameObject go = Instantiate<GameObject>(pathPrefab3);
  224. // Path path = go.GetComponent<Path>();
  225. // paths.Add(path);
  226. // nextPosition = path.attachPoint.transform.position;
  227. // RY += 90;
  228. // //var nextTransform = path.attachPoint;
  229. // //fix all the offsets------------
  230. // if ((RY) == 0)
  231. // nextPosition.z += .5f;
  232. // else if ((RY) == 90 || RY == -270)
  233. // nextPosition.x += .5f;
  234. // else if ((RY) == 180 || RY == -180)
  235. // nextPosition.z -= .5f;
  236. // else if (RY == -90)
  237. // nextPosition.x -= .5f;
  238. // //that sucked :)----------------
  239.  
  240. // go.transform.position = nextPosition;// - path.startPoint.transform.position;
  241. // go.transform.rotation = Quaternion.Euler(0, RY, 0);
  242. // RY += 90;
  243.  
  244. // nextPosition = path.attachPoint.transform.position;
  245. // sameTurnsR += 1;
  246. // if (sameTurnsL > 0)
  247. // {
  248. // sameTurnsL -= 1;
  249. // }
  250. // lastStraight = false;
  251. // }
  252. // else
  253. // {
  254. // GameObject go = Instantiate<GameObject>(pathPrefab);
  255. // Path path = go.GetComponent<Path>();
  256. // paths.Add(path);
  257. // nextPosition = path.attachPoint.transform.position;
  258. // //var nextTransform = path.attachPoint;
  259. // go.transform.position = nextPosition;// - path.startPoint.transform.position;
  260. // go.transform.rotation = Quaternion.Euler(0, RY, 0);
  261. // nextPosition = path.attachPoint.transform.position;
  262. // lastStraight = true;
  263. // sameTurnsR -= 1;
  264. // }
  265. // }
  266. //}
  267. //void removeFirstPath()
  268. //{
  269. // Path first = paths[0];
  270. // paths.RemoveAt(0);
  271. // Destroy(first);
  272. //}
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement