Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Button

This is a clickable button.
Read time 7 minutesLast updated 2 days ago

Definition

public class Button : TextElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IVisualElementScheduler, IBindable, INotifyValueChanged<string>, ITextEdition, ITextElementExperimentalFeatures, IExperimentalFeatures, ITextSelection

Remarks

A Button has a text label element that can respond to pointer and mouse events. You can add an icon to pair it with the text by assigning a Background (Texture, RenderTexture, Sprite or Vector Image) to the iconImage API or icon-image UXML property. Please note that by providing an icon image, this will automatically update the Button's hierarchy to contain an Image and a text label element.
By default, a single left mouse click activates the Button's Clickable property button. To remove this activator, or add more activators, modify the
clickable.activators
property. For details, see ManipulatorActivationFilter.
To bind a Button's text value to the contents of a variable, set the
binding-path
property in the UXML file, or the
bindingPath
property in the C# code, to a string that contains the variable name.
For more information, refer to UXML element Button.

Static Fields

Value

Description

iconOnlyUssClassNameThe USS class name for Button elements with an icon only, no text.
iconUssClassNameThe USS class name for Button elements with an icon.
imageUSSClassNameThe USS class name of the image element that will be used to display the icon texture.
ussClassNameUSS class name of elements of this type.

Constructors

Constructor

Description

Button()Constructs a Button.
Button(System.Action)Constructs a button with an Action that is triggered when the button is clicked.
Button(UnityEngine.UIElements.Background,System.Action)Constructs a button with a Background and an Action. The image definition will be used to represent an icon while the Action is triggered when the button is clicked.

Properties

Property

Description

clickableClickable MouseManipulator for this Button.
iconImageThe Texture, Sprite, or VectorImage that will represent an icon within a Button element.

Events

Member

Description

clickedCallback triggered when the button is clicked.

Inheritance

Inherited Members