Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PathFinder {
- public void FindNewPath()
- {
- Vector3 GoTo = new Vector3(0, 0, 0);
- List<float> travDistances = new List<float>();
- List<string> finalPath = new List<string>();
- float minDistance = 0;
- var z2 = "";
- GameObject r = GameObject.Find("r1");
- RegionDetails r2 = r.GetComponent<RegionDetails>();
- for (var i = 0; i < r2.neighborList.Count; i++)
- {
- if (r2.neighborList[i] != "0")
- {
- GameObject z = GameObject.Find(r2.neighborList[i]);
- Debug.Log(z);
- float dist = Vector3.Distance(GoTo, z.transform.position);
- travDistances.Add(dist);
- Debug.Log(dist);
- if (minDistance == 0)
- {
- minDistance = dist;
- z2 = r2.neighborList[i];
- }
- else if (dist < minDistance)
- {
- minDistance = dist;
- z2 = r2.neighborList[i];
- }
- }
- else
- {
- break;
- }
- Debug.Log(minDistance);
- Debug.Log(z2);
- finalPath.Add(z2);
- }
- Debug.Log("Travel Distances Stored:" + travDistances.Count);
- travDistances.Clear();
- var z3 = "";
- GameObject t = GameObject.Find(z2);
- RegionDetails t2 = t.GetComponent<RegionDetails>();
- minDistance = 0;
- for (var i = 0; i < t2.neighborList.Count; i++)
- {
- if (t2.neighborList[i] != "0")
- {
- GameObject z = GameObject.Find(t2.neighborList[i]);
- Debug.Log(z);
- float dist = Vector3.Distance(GoTo, z.transform.position);
- travDistances.Add(dist);
- Debug.Log(dist);
- if (minDistance == 0)
- {
- minDistance = dist;
- z3 = t2.neighborList[i];
- }
- else if (dist < minDistance)
- {
- minDistance = dist;
- z3 = t2.neighborList[i];
- }
- }
- else
- {
- break;
- }
- Debug.Log(minDistance);
- Debug.Log(z3);
- finalPath.Add(z3);
- }
- Debug.Log("Travel Distances Stored:" + travDistances.Count);
- travDistances.Clear();
- var z4 = "";
- GameObject y = GameObject.Find(z3);
- RegionDetails y2 = y.GetComponent<RegionDetails>();
- minDistance = 0;
- for (var i = 0; i < y2.neighborList.Count; i++)
- {
- if (y2.neighborList[i] != "0")
- {
- GameObject z = GameObject.Find(y2.neighborList[i]);
- Debug.Log(z);
- float dist = Vector3.Distance(GoTo, z.transform.position);
- travDistances.Add(dist);
- Debug.Log(dist);
- if (minDistance == 0)
- {
- minDistance = dist;
- z4 = y2.neighborList[i];
- }
- else if (dist < minDistance)
- {
- minDistance = dist;
- z4 = y2.neighborList[i];
- }
- }
- else
- {
- break;
- }
- Debug.Log(minDistance);
- Debug.Log(z4);
- finalPath.Add(z4);
- }
- Debug.Log("Travel Distances Stored:" + travDistances.Count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement