Home › Page › UghButton


Inherits from UghControl

Each UghButton runs a function when you press it. They can be combined with an UghPublisher or used on their own. For more information on the relationship between UghButtons and UghPublishers, see the UghPublisher tutorial page.

name type description
autoSizeCollider boolean Do we automatically resize the collider for this button?
mouseOver UghSpriteDefinition The sprite definition for when the mouse hovers over the button
pressed UghSpriteDefinition The sprite definition for when the mouse is clicking on or a finger is tapping on the button
name type description
OnDown event An event fired when the button is pressed down
OnUghInputDown void Called when the mouse clicks or a finger taps on this button
OnUghInputUp void Called when the mouse or finger drags off this button
OnUghInputUpAsButton void Called when the mouse stops clicking or a finger lifts up when over this button
OnPressed event An event fired when the button is released with the input over the button, at the same time as OnUghInputAsButton
Inherited Variables
name type description
anchor UghSprite.Anchor The corner or custom point that the UghControl is anchored to
customAnchorOffset Vector3 The offset values for a custom anchor
flippedHorizontal boolean Is the UghSprite flipped horizonally?
flippedVertical boolean Is the UghSprite flipped vertically?
HotFingerID int The ID of the finger interacting with this control
isLegalControl boolean Is this a legal control?
normal UghSpriteDefinition The default UghSpriteDefinition for this button
Prototype UghSpritePrototype The current UghSpritePrototype for this button
Offset Vector3 The offset of the UghSprite
Inherited Functions
name type description
GetLocalCenter Vector3 Returns the local center of the UghControl
GetLocalOrigin Vector3 Returns the local origin of the UghControl
GetParentPublisher UghPublisher Returns the UghPublisher which this UghControl belongs to, or null if none
UpdateMesh void Updates this control's mesh
Inherited Class Variables
name type description
Anchor enum Enum for different common anchor positions
AnchorToTextAnchor TextAnchor Converts an Anchor enum into a TextAnchor enum
TextAnchorToAnchor UghSprite.Anchor Converts a TextAnchor enum into an Anchor enum
theOnlyLegalControls UghControl[] Array of all currently legal controls
Inherited Class Functions
name type description
ForceUpdateAllUghSpriteMeshes void Forces every UghSprite's mesh to update
GetOffsetForAnchor Vector3 Returns the Vector3 offset for a given Anchor value


Understanding the UghButton class

The functions OnUghInputDown, OnUghInputUp, and OnUghInputUpAsButton are called by the UghInput object in the scene. OnUghInputDown is called when the user clicks on or puts their finger on the button. OnUghInputUp is called when the input leaves the button, whether because the input stopped entirely or just moved off of the button. OnUghInputUpAsButton only fires if the input started above the button and ends above the button. This is also the function that means the button was “actually pressed” and the function set in its parent UghPublisher will be run.

public override IEnumerator OnUghInputDown();
public override void OnUghInputUp();
public override void OnUghInputUpAsButton();

There are two events on every UghButton: OnDown and OnPressed. In the event that you want to use an UghButton element without a parent UghPublisher, you should register for these events. The OnDown event will fire when the down state of the button changes. The event passes the button itself and a boolean for the state of the button. If you are registering for the OnDown event and only want your program to do something when the down state changes to true, make sure to check this boolean.

public event System.Action<Ughbutton,bool> OnDown;
public event System.Action OnPressed;

The OnPressed event fires under exactly the same circumstances that OnUghInputUpAsButton runs.