tmoneygames

PatrolPath.cs

Jun 22nd, 2021 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace RPG.Control
  6. {
  7.     public class PatrolPath : MonoBehaviour
  8.     {
  9.         // Variables
  10.         const float waypointGizmoRadius = 0.3f;
  11.  
  12.         private void OnDrawGizmos()
  13.         {
  14.             for(int i = 0; i < transform.childCount; i++)
  15.             {
  16.                 int j = GetNextIndex(i);
  17.                 Gizmos.DrawSphere(GetWaypoint(i), waypointGizmoRadius);
  18.                 Gizmos.DrawLine(GetWaypoint(i), GetWaypoint(j));
  19.             }
  20.         }
  21.  
  22.         public int GetNextIndex(int i)
  23.         {
  24.             if(i + 1 == transform.childCount)
  25.             {
  26.                 return 0;
  27.             }
  28.             return i + 1;
  29.         }
  30.  
  31.         public Vector3 GetWaypoint(int i)
  32.         {
  33.             return transform.GetChild(i).position;
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment