Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

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

Handles.Button

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

Sumbission failed

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

Close

Cancel

Switch to Manual
public static function Button(position: Vector3, direction: Quaternion, size: float, pickSize: float, capFunc: Handles.DrawCapFunction): bool;
public static bool Button(Vector3 position, Quaternion direction, float size, float pickSize, Handles.DrawCapFunction capFunc);

Parameters

Description

Make a 3D Button.

This works like a normal GUI.Button, but it has a 3D position and is drawn by a handle function

Note: Use HandleUtility.GetHandleSize where you might want to have constant screen-sized handles.


Button Handle as a rectangle in the Scene View.

	// Create a simple button on 3D space and when the user clicks over the handle
	// it prints a message.
	
	@CustomEditor (ButtonChecker)
	class ButtonHandle extends Editor {
		function OnSceneGUI () {
	        target.checkButton = 
	        	Handles.Button(target.transform.position + Vector3(0,2,0),
	        			Quaternion.identity,
	        			3,
	        			3,
	        			Handles.DrawSolidRectangleWithOutline);	
	    }
	}

And the script attached to this handle:

	// Usage: Place this script on the object you want to create the button on.
	// When the script is placed, just press "Play" and click the rectangle
	// that appears over the GameObject
	
	var checkButton : boolean = true;
	
	function Update() {
		if(checkButton)
			Debug.Log("The handle button has been pressed!");
	}