Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CurrentNode : MonoBehaviour {
- public GameObject currentNode;
- // Use this for initialization
- void Start () {
- SetCurrentNode ();
- }
- void SetCurrentNode(){
- float shortestDistance = Mathf.Infinity;
- foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Node")) {
- float dist = (obj.transform.position - transform.position).magnitude;
- if(dist < shortestDistance){
- shortestDistance = dist;
- currentNode = obj;
- }
- }
- }
- // Update is called once per frame
- void Update () {
- SetCurrentNode ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement