Legacy Documentation: Version 5.5
LanguageEnglish
  • C#
  • JS

Script language

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

Handles.DrawSolidRectangleWithOutline

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 DrawSolidRectangleWithOutline(verts: Vector3[], faceColor: Color, outlineColor: Color): void;
public static void DrawSolidRectangleWithOutline(Vector3[] verts, Color faceColor, Color outlineColor);

Parameters

verts The 4 vertices of the rectangle in world coordinates.
faceColor The color of the rectangle's face.
outlineColor The outline color of the rectangle.

Description

Draw a solid outlined rectangle in 3D space.


Solid rectangle with a black outline in the Scene View.

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

#pragma strict
@CustomEditor(DrawSolidRect)
public class DrawSolidRectEditor extends Editor {
	function OnSceneGUI() {
		var t: DrawSolidRect = target as DrawSolidRect;
		Handles.color = Color.blue;
		Handles.Label(t.transform.position + Vector3.up * 2, t.transform.position.ToString() + "\nRange: " + t.range.ToString());
		Handles.BeginGUI();
		GUILayout.BeginArea(new Rect(Screen.width - 100, Screen.height - 80, 90, 50));
		if (GUILayout.Button("Reset Range"))
			t.range = 5;
		GUILayout.EndArea();
		Handles.EndGUI();
		var pos: Vector3 = t.transform.position;
		var verts: Vector3[] = [new Vector3(pos.x - t.range, pos.y, pos.z - t.range), new Vector3(pos.x - t.range, pos.y, pos.z + t.range), new Vector3(pos.x + t.range, pos.y, pos.z + t.range), new Vector3(pos.x + t.range, pos.y, pos.z - t.range)];
		Handles.DrawSolidRectangleWithOutline(verts, new Color(1, 1, 1, 0.2f), new Color(0, 0, 0, 1));
		Handles.color = Color.white;
		for (var posCube: Vector3 in verts)
			t.range = Handles.ScaleValueHandle(t.range, posCube, Quaternion.identity, 1, Handles.CubeCap, 1);
	}
}
using UnityEngine;
using UnityEditor;

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

Handles.color = Color.blue; Handles.Label( t.transform.position + Vector3.up * 2, t.transform.position.ToString( ) + "\nRange: " + t.range.ToString( ) );

Handles.BeginGUI( ); GUILayout.BeginArea( new Rect( Screen.width - 100, Screen.height - 80, 90, 50 ) );

if( GUILayout.Button( "Reset Range" ) ) t.range = 5;

GUILayout.EndArea( ); Handles.EndGUI( );

Vector3 pos = t.transform.position;

Vector3[] verts = new Vector3[] { new Vector3(pos.x - t.range,pos.y,pos.z-t.range), new Vector3(pos.x-t.range,pos.y,pos.z + t.range), new Vector3(pos.x+t.range,pos.y,pos.z + t.range), new Vector3(pos.x+t.range,pos.y,pos.z-t.range) };

Handles.DrawSolidRectangleWithOutline( verts, new Color( 1, 1, 1, 0.2f ), new Color( 0, 0, 0, 1 ) ); Handles.color = Color.white;

foreach( Vector3 posCube in verts ) t.range = Handles.ScaleValueHandle( t.range, posCube, Quaternion.identity, 1, Handles.CubeCap, 1 ); } }

...and place this script on the object where you want the SolidRectangle to appear:

#pragma strict
@ExecuteInEditMode
public class DrawSolidRect extends MonoBehaviour {
	public var range: float = 5;
}
using UnityEngine;

[ExecuteInEditMode] public class DrawSolidRect : MonoBehaviour { public float range = 5; }