Advertisement
dronkowitz

PatrolPath.cs

Nov 30th, 2022
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PatrolPath : MonoBehaviour
  6. {
  7.     const float waypointGizmoRadius = 0.3f;
  8.  
  9.     private void OnDrawGizmos()
  10.     {
  11.         for(int i = 0; i < transform.childCount; i++)
  12.         {
  13.             transform.GetChild(i).gameObject.name = "Point " + (i+1).ToString("00");
  14.             int j = GetNextIndex(i);
  15.             Gizmos.color = new Color(0, 0, 1, 0.5f);
  16.             Gizmos.DrawSphere(GetWayPoint(i), waypointGizmoRadius);
  17.             Gizmos.color = new Color(0.2f, 0.2f, 1);
  18.             Gizmos.DrawLine(GetWayPoint(i), GetWayPoint(j));
  19.         }
  20.     }
  21.     public int GetNextIndex(int i)
  22.     {
  23.         if (i + 1 == transform.childCount)
  24.         {
  25.             return 0;
  26.         }
  27.         return i + 1;
  28.     }
  29.     public Vector3 GetWayPoint(int i)
  30.     {
  31.         return transform.GetChild(i).position;
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement