Version: 5.5 (switch to 5.6b)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Handles.DrawDottedLines

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function DrawDottedLines(lineSegments: Vector3[], screenSpaceSize: float): void;
public static void DrawDottedLines(Vector3[] lineSegments, float screenSpaceSize);

Parameters

lineSegments A list of pairs of points that represent the start and end of line segments.
screenSpaceSize The size in pixels for the lengths of the line segments and the gaps between them.

Description

Draw a list of dotted line segments.


Draw multiple dotted lines in Scene view.

The following example uses DrawDottedLines to draw a line between GameObjects defined in a list.

To use this example, save the following script into the Assets/Editor folder:

#pragma strict
@CustomEditor(DrawDottedConnectedLines)
public class DrawDottedConnectedLinesEditor extends Editor {
	function OnSceneGUI() {
		var t: DrawDottedConnectedLines = target as DrawDottedConnectedLines;
		if (t == null || t.GameObjects == null)return ;
		var lineSegments: Vector3[] = new Vector3[t.GameObjects.Length * 2];
		var pointIndex: int = 0;
		for (var i: int = 0; i < t.GameObjects.Length - 1; i++) {
			if (t.GameObjects[i] != null && t.GameObjects[i + 1] != null) {
				lineSegments[pointIndex++] = t.GameObjects[i].transform.position;
				lineSegments[pointIndex++] = t.GameObjects[i + 1].transform.position;
			}
		}
		Handles.DrawDottedLines(lineSegments, t.DashSize);
	}
}
using UnityEngine;
using UnityEditor;

[CustomEditor( typeof( DrawDottedConnectedLines ) )] public class DrawDottedConnectedLinesEditor : Editor { void OnSceneGUI( ) { DrawDottedConnectedLines t = target as DrawDottedConnectedLines;

if( t == null || t.GameObjects == null ) return;

Vector3[] lineSegments = new Vector3[t.GameObjects.Length * 2]; int pointIndex = 0;

for( int i = 0; i < t.GameObjects.Length - 1; i++ ) { if( t.GameObjects[i] != null && t.GameObjects[i+1] != null ) { lineSegments[pointIndex++] = t.GameObjects[i].transform.position; lineSegments[pointIndex++] = t.GameObjects[i+1].transform.position; } }

Handles.DrawDottedLines( lineSegments, t.DashSize ); } }

...then attach this script to the anchor GameObject which you would like to see lines come from. Drop GameObjects you would like the lines to go to into the array in the script's inspector, and adjust the gap between the dotted lines accordingly:

#pragma strict
@ExecuteInEditMode
public class DrawDottedConnectedLines extends MonoBehaviour {
	public var GameObjects: GameObject[];
	public var DashSize: float = 4;
}
using UnityEngine;
          
[ExecuteInEditMode]
public class DrawDottedConnectedLines : MonoBehaviour
{
	public GameObject[] GameObjects;
	public float DashSize = 4;
}

public static function DrawDottedLines(points: Vector3[], segmentIndices: int[], screenSpaceSize: float): void;
public static void DrawDottedLines(Vector3[] points, int[] segmentIndices, float screenSpaceSize);

Parameters

points A list of points.
segmentIndices A list of pairs of indices to the start and end points of the line segments.
screenSpaceSize The size in pixels for the lengths of the line segments and the gaps between them.

Description

Draw a list of indexed dotted line segments.

The following example uses DrawDottedLines to draw a line between objects defined in a list. To use this example, save the following script into the Assets/Editor folder:

#pragma strict
@CustomEditor(DrawDottedConnectedLinesUsingPoints)
public class DrawDottedConnectedLinesUsingPointsEditor extends Editor {
	function OnSceneGUI() {
		var t: DrawDottedConnectedLinesUsingPoints = target as DrawDottedConnectedLinesUsingPoints;
		if (t == null || t.GameObjects == null)return ;
		var points: Vector3[] = new Vector3[t.GameObjects.Length];
		var segmentIndices: int[] = new int[t.GameObjects.Length * 2];
		var pointsIndex: int = 0;
		for (var i: int = 0; i < t.GameObjects.Length; i++) {
			if (t.GameObjects[i] != null)
				points[pointsIndex++] = t.GameObjects[i].transform.position;
		}
		for (var i: int = 0; i < pointsIndex - 1; i++) {
			var segmentIndex: int = i * 2;
			segmentIndices[segmentIndex] = i;
			segmentIndices[segmentIndex + 1] = i + 1;
		}
		Handles.DrawDottedLines(points, segmentIndices, t.DashSize);
	}
}
using UnityEngine;
using UnityEditor;

[CustomEditor( typeof( DrawDottedConnectedLinesUsingPoints ) )] public class DrawDottedConnectedLinesUsingPointsEditor : Editor { void OnSceneGUI( ) { DrawDottedConnectedLinesUsingPoints t = target as DrawDottedConnectedLinesUsingPoints;

if( t == null || t.GameObjects == null ) return;

Vector3[] points = new Vector3[t.GameObjects.Length]; int[] segmentIndices = new int[t.GameObjects.Length * 2]; int pointsIndex = 0;

for( int i = 0; i < t.GameObjects.Length; i++ ) { if( t.GameObjects[i] != null ) points[pointsIndex++] = t.GameObjects[i].transform.position; }

for( int i = 0; i < pointsIndex - 1; i++ ) { int segmentIndex = i * 2;

segmentIndices[segmentIndex] = i; segmentIndices[segmentIndex+1] = i+1; }

Handles.DrawDottedLines(points, segmentIndices, t.DashSize ); } }

...then attach this script to the anchor object which you would like to see lines eminate from. Drop GameObjects you would like lines drawing to into the array in the script's inspector, and adjust the gap between the dotted lines accordingly:

#pragma strict
@ExecuteInEditMode
public class DrawDottedConnectedLinesUsingPoints extends MonoBehaviour {
	public var GameObjects: GameObject[];
	public var DashSize: float = 4;
}
using UnityEngine;

[ExecuteInEditMode] public class DrawDottedConnectedLinesUsingPoints : MonoBehaviour { public GameObject[] GameObjects; public float DashSize = 4; }