TechManDylan

Route

Sep 18th, 2021 (edited)
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Route : MonoBehaviour
  6. {
  7.  
  8.     Transform[] childObjects;
  9.     public List<Transform> childNodeList = new List<Transform>();
  10.  
  11.     void Start()
  12.     {
  13.         FillNodes();
  14.     }
  15.  
  16.     //Should be removed when done building.
  17.     private void OnDrawGizmos()
  18.     {
  19.         Gizmos.color = Color.green;
  20.  
  21.         FillNodes();
  22.  
  23.         for (int i = 0; i < childNodeList.Count; i++)
  24.         {
  25.             Vector3 currentPos = childNodeList[i].position;
  26.             if (i > 0)
  27.             {
  28.                 Vector3 prevPos = childNodeList[i - 1].position;
  29.                 Gizmos.DrawLine(prevPos, currentPos);
  30.             }
  31.         }
  32.     }
  33.  
  34.     void FillNodes()
  35.     {
  36.         childNodeList.Clear();
  37.         childObjects = GetComponentsInChildren<Transform>();
  38.         foreach(Transform child in childObjects)
  39.         {
  40.             if (child != this.transform)
  41.             {
  42.                 childNodeList.Add(child);
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Add Comment
Please, Sign In to add comment