public void SetAlgorithms() { int i = 0; foreach (AlgorithmData algorithmData in levelData.algorithms) { GameObject algGridElement; if (algorithmGrid.transform.childCount < levelData.algorithms.Count) { algGridElement = (GameObject)Instantiate(Resources.Load("PanelAlgorithm"), algorithmGrid.transform); } else { algGridElement = algorithmGrid.transform.GetChild(i).gameObject; } algGridElement.transform.Find("TextName").GetComponent <Text>().text = "Name: " + algorithmData.name; algGridElement.transform.Find("TextFieldCount").GetComponent <Text>().text = "Checked tiles: " + algorithmData.checkedNodesCount; algGridElement.transform.Find("TextTime").GetComponent <Text>().text = "Time: " + algorithmData.time.ToString("0.000") + " ms"; AlgorithmPath algRun = algGridElement.transform.GetComponentInChildren <AlgorithmPath>(); algRun.path = algorithmData.path; algRun.start = gridManager.GetStart(); algRun.color = GetRunnerColor(algorithmData.name); algRun.gridManager = gridManager; i++; } gridManager.SetMap(levelData.blocked); }
// Use this for initialization void Start() { //objective = this.transform.position; nodesList = start.nodes[1].nodes; path = AlgorithmPath.DepthwiseSearch(start, end); myPath = new List <Node> (path); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { //myPath = new List<Node> (); if (myPath.Count == 0) { Debug.Log("New list"); } Debug.Log("CurrentNode " + currentNode); end = GetNode(hit); Debug.Log(GetNode(hit).name); } } Debug.Log("End " + end.name); path = AlgorithmPath.DepthwiseSearch(start, end); myPath = new List <Node> (path); transform.LookAt(myPath [currentNode].transform); transform.Translate(transform.forward * speed * Time.deltaTime, Space.World); float distance = Vector3.Distance(myPath[currentNode].transform.position, transform.position); if (distance < threshold) { currentNode++; //Debug.Log ("CurrentPlus " + currentNode); currentNode %= myPath.Count; //Debug.Log ("Current " + currentNode); } }