SHARE
TWEET

CurrentNode

a guest Jan 18th, 2014 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top