Advertisement
Guest User

CurrentNode

a guest
Jan 18th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CurrentNode : MonoBehaviour {
  5.  
  6.     public GameObject currentNode;
  7.  
  8.     // Use this for initialization
  9.     void Start () {
  10.         SetCurrentNode ();
  11.     }
  12.  
  13.     void SetCurrentNode(){
  14.         float shortestDistance = Mathf.Infinity;
  15.        
  16.         foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Node")) {
  17.            
  18.             float dist = (obj.transform.position - transform.position).magnitude;
  19.             if(dist < shortestDistance){
  20.                 shortestDistance = dist;
  21.                 currentNode = obj;
  22.             }
  23.         }
  24.     }
  25.    
  26.     // Update is called once per frame
  27.     void Update () {
  28.         SetCurrentNode ();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement