Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PathFinder {
  6.  
  7.  
  8. public void FindNewPath()
  9. {
  10. Vector3 GoTo = new Vector3(0, 0, 0);
  11. List<float> travDistances = new List<float>();
  12. List<string> finalPath = new List<string>();
  13. float minDistance = 0;
  14. var z2 = "";
  15.  
  16. GameObject r = GameObject.Find("r1");
  17. RegionDetails r2 = r.GetComponent<RegionDetails>();
  18.  
  19. for (var i = 0; i < r2.neighborList.Count; i++)
  20. {
  21. if (r2.neighborList[i] != "0")
  22. {
  23. GameObject z = GameObject.Find(r2.neighborList[i]);
  24. Debug.Log(z);
  25. float dist = Vector3.Distance(GoTo, z.transform.position);
  26. travDistances.Add(dist);
  27. Debug.Log(dist);
  28.  
  29. if (minDistance == 0)
  30. {
  31. minDistance = dist;
  32. z2 = r2.neighborList[i];
  33. }
  34. else if (dist < minDistance)
  35. {
  36. minDistance = dist;
  37. z2 = r2.neighborList[i];
  38. }
  39. }
  40. else
  41. {
  42. break;
  43. }
  44. Debug.Log(minDistance);
  45. Debug.Log(z2);
  46. finalPath.Add(z2);
  47. }
  48.  
  49. Debug.Log("Travel Distances Stored:" + travDistances.Count);
  50.  
  51. travDistances.Clear();
  52.  
  53. var z3 = "";
  54. GameObject t = GameObject.Find(z2);
  55. RegionDetails t2 = t.GetComponent<RegionDetails>();
  56. minDistance = 0;
  57.  
  58. for (var i = 0; i < t2.neighborList.Count; i++)
  59. {
  60. if (t2.neighborList[i] != "0")
  61. {
  62. GameObject z = GameObject.Find(t2.neighborList[i]);
  63. Debug.Log(z);
  64. float dist = Vector3.Distance(GoTo, z.transform.position);
  65. travDistances.Add(dist);
  66. Debug.Log(dist);
  67.  
  68. if (minDistance == 0)
  69. {
  70. minDistance = dist;
  71. z3 = t2.neighborList[i];
  72. }
  73. else if (dist < minDistance)
  74. {
  75. minDistance = dist;
  76. z3 = t2.neighborList[i];
  77. }
  78. }
  79. else
  80. {
  81. break;
  82. }
  83. Debug.Log(minDistance);
  84. Debug.Log(z3);
  85. finalPath.Add(z3);
  86. }
  87.  
  88. Debug.Log("Travel Distances Stored:" + travDistances.Count);
  89.  
  90. travDistances.Clear();
  91.  
  92. var z4 = "";
  93. GameObject y = GameObject.Find(z3);
  94. RegionDetails y2 = y.GetComponent<RegionDetails>();
  95. minDistance = 0;
  96.  
  97. for (var i = 0; i < y2.neighborList.Count; i++)
  98. {
  99. if (y2.neighborList[i] != "0")
  100. {
  101. GameObject z = GameObject.Find(y2.neighborList[i]);
  102. Debug.Log(z);
  103. float dist = Vector3.Distance(GoTo, z.transform.position);
  104. travDistances.Add(dist);
  105. Debug.Log(dist);
  106.  
  107. if (minDistance == 0)
  108. {
  109. minDistance = dist;
  110. z4 = y2.neighborList[i];
  111. }
  112. else if (dist < minDistance)
  113. {
  114. minDistance = dist;
  115. z4 = y2.neighborList[i];
  116. }
  117. }
  118. else
  119. {
  120. break;
  121. }
  122. Debug.Log(minDistance);
  123. Debug.Log(z4);
  124. finalPath.Add(z4);
  125. }
  126.  
  127. Debug.Log("Travel Distances Stored:" + travDistances.Count);
  128.  
  129. }
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement