Search Unity

Draw line between gizmos

Discussion in 'Scripting' started by DarkSoul, May 12, 2010.

  1. DarkSoul

    DarkSoul

    Joined:
    Dec 24, 2009
    Posts:
    37
    Hello.
    I'm trying draw a line between several Gizmos in the map (waypoints), but I don't know how to do this.
    My current code is:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class WayPoint : MonoBehaviour {
    6.     //Array
    7.     //ArrayList Nwaypoints;
    8.     //Variables
    9.     private bool ActiveBucle = true;
    10.     private int WaypointID;
    11.  
    12.     //Draw gizmo waypoint
    13.     void OnDrawGizmos()
    14.     {
    15.         Gizmos.DrawIcon(this.transform.position, "WayPoint.tif");
    16.     }
    17.     //Draw line between waypoints
    18.     void OnDrawGizmosSelected()
    19.     {
    20.         DrawThePath();
    21.     }
    22.  
    23.     GameObject DrawThePath()
    24.     {
    25.         GameObject[] FindWaypoints = GameObject.FindGameObjectsWithTag("Waypoint");
    26.         foreach (GameObject CurrentID in FindWaypoints)
    27.         {
    28.             if (Physics.Linecast(CurrentID.transform.position, CurrentID.transform.position))
    29.             {
    30.                 Gizmos.color = Color.red;
    31.                 Gizmos.DrawLine(CurrentID.transform.position, CurrentID.transform.position);
    32.             }
    33.             else
    34.             {
    35.                 Gizmos.color = Color.white;
    36.                 Gizmos.DrawLine(CurrentID.transform.position, CurrentID.transform.position);
    37.             }
    38.         }
    39.         return null;
    40.     }
    41. }
    42.  
    I'm lost with this, does anyone help me?
     
  2. npushkin

    npushkin

    Joined:
    Jul 12, 2013
    Posts:
    6
    You try to draw from current to current point: CurrentID.transform.position, CurrentID.transform.position.
    !PREV_ID!.transform.position, CurrentID.transform.position.
    And linecast too. Good luck =)
     
  3. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    258
    That user was last seen over 9 years ago...

    Please check the date of the last post next time you post something.
     
    PrinceB12 likes this.