A standard button that sends an event when clicked.
Inherited MembersComponent.GetComponentIndex()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, InstantiateParameters)
Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Namespace: UnityEngine.UI Assembly: UnityEngine.UI.dll Syntax[AddComponentMenu("UI/Button", 30)]
public class Button : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IPointerClickHandler, ISubmitHandler, IEventSystemHandler
Constructors Button() Declaration Properties onClick
UnityEvent that is triggered when the button is pressed. Note: Triggered on MouseUp after MouseDown on the same object.
Declarationpublic Button.ButtonClickedEvent onClick { get; set; }
Property Value Examples
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ClickExample : MonoBehaviour
{
public Button yourButton;
void Start()
{
Button btn = yourButton.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void TaskOnClick()
{
Debug.Log("You have clicked the button!");
}
}
Methods OnPointerClick(PointerEventData)
Call all registered IPointerClickHandlers. Register button presses using the IPointerClickHandler. You can also use it to tell what type of click happened (left, right etc.). Make sure your Scene has an EventSystem.
Declarationpublic virtual void OnPointerClick(PointerEventData eventData)
Parameters Type Name Description PointerEventData eventData
Pointer Data associated with the event. Typically by the event system.
Examples//Attatch this script to a Button GameObject
using UnityEngine;
using UnityEngine.EventSystems;
public class Example : MonoBehaviour, IPointerClickHandler
{
//Detect if a click occurs
public void OnPointerClick(PointerEventData pointerEventData)
{
//Use this to tell when the user right-clicks on the Button
if (pointerEventData.button == PointerEventData.InputButton.Right)
{
//Output to console the clicked GameObject's name and the following message. You can replace this with your own actions for when clicking the GameObject.
Debug.Log(name + " Game Object Right Clicked!");
}
//Use this to tell when the user left-clicks on the Button
if (pointerEventData.button == PointerEventData.InputButton.Left)
{
Debug.Log(name + " Game Object Left Clicked!");
}
}
}
OnSubmit(BaseEventData)
Call all registered ISubmitHandler.
Declarationpublic virtual void OnSubmit(BaseEventData eventData)
Parameters Type Name Description BaseEventData eventData
Associated data with the event. Typically by the event system.
ImplementsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4