Select your preferred scripting language. All code snippets will be displayed in this language.
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.
CloseFor 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.
Closep1 | The start point. |
p2 | The end point. |
screenSpaceSize | The size in pixels for the lengths of the line segments and the gaps between them. |
Draw a dotted line from p1 to p2.
Draw Line in the Scene view.
The following example uses DrawDottedLine to draw a line between a GameObject and the Game Objects defined in a list.
To use this example, save the following script into the Assets/Editor folder:
#pragma strict @CustomEditor(DrawDottedConnectedLine) public class DrawDottedConnectedLineEditor extends Editor { function OnSceneGUI() { var t: DrawDottedConnectedLine = target as DrawDottedConnectedLine; if (t == null || t.GameObjects == null)return ; var center: Vector3 = t.transform.position; for (var i: int = 0; i < t.GameObjects.Length; i++) { if (t.GameObjects[i] != null) Handles.DrawDottedLine(center, t.GameObjects[i].transform.position, t.DashSize); } } }
using UnityEngine; using UnityEditor;
[CustomEditor( typeof( DrawDottedConnectedLine ) )] public class DrawDottedConnectedLineEditor : Editor { void OnSceneGUI( ) { DrawDottedConnectedLine t = target as DrawDottedConnectedLine;
if( t == null || t.GameObjects == null ) return;
Vector3 center = t.transform.position;
for( int i = 0; i < t.GameObjects.Length; i++ ) { if( t.GameObjects[i] != null ) Handles.DrawDottedLine( center, t.GameObjects[i].transform.position, 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 DrawDottedConnectedLine extends MonoBehaviour { public var GameObjects: GameObject[]; public var DashSize: float = 4; }
using UnityEngine; [ExecuteInEditMode] public class DrawDottedConnectedLine : MonoBehaviour { public GameObject[] GameObjects; public float DashSize = 4; }