Advertisement
Guest User

Node

a guest
Jan 18th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Node : MonoBehaviour {
  6.  
  7.     public GameObject[] neighbors;
  8.  
  9.     public GameObject goal;
  10.  
  11.     void OnDrawGizmos(){
  12.         Gizmos.DrawWireCube (transform.position, Vector2.zero);
  13.  
  14.         foreach(GameObject neighbor in neighbors){
  15.             Gizmos.DrawLine(transform.position, neighbor.transform.position);
  16.             Gizmos.DrawWireSphere(neighbor.transform.position, 0.25f);
  17.         }
  18.  
  19.         if (goal) {
  20.             GameObject current = gameObject;
  21.             Stack<GameObject> path = DijkstraAlgorithm.Dijkstra(GameObject.FindGameObjectsWithTag("Node"), gameObject, goal);
  22.  
  23.             Debug.Log ("Got here:");
  24.             Debug.Log (path);
  25.  
  26.             foreach(GameObject obj in path){
  27.                 Debug.Log ("Got here also:");
  28.                 Gizmos.color = Color.green;
  29.                 Gizmos.DrawWireSphere(obj.transform.position,1.0f);
  30.                 Gizmos.DrawLine(current.transform.position, obj.transform.position);
  31.                 current = obj;
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement