UI Button: Play sound on button down

This commit is contained in:
Nahuel Rocchetti 2024-07-09 04:28:56 -03:00
parent 790a64d457
commit 561917e60d

View file

@ -17,7 +17,7 @@ namespace OpenTS2.UI
public class UIButtonComponent : UIComponent, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
{
/// <summary>
/// Triggers when this button is clicked. Boolean argument specifies whether it was a double click.
/// Triggers when this button is clicked.
/// </summary>
public Action OnClick;
public bool GreyedOut = false;
@ -87,6 +87,7 @@ namespace OpenTS2.UI
{
if (eventData.button != PointerEventData.InputButton.Left && eventData.button != PointerEventData.InputButton.Right)
return;
AudioManager.Instance.PlayUISound(ClickSound);
_held = true;
}
@ -95,16 +96,8 @@ namespace OpenTS2.UI
if (eventData.button != PointerEventData.InputButton.Left && eventData.button != PointerEventData.InputButton.Right)
return;
if (_held && _hovering)
{
Click();
}
OnClick?.Invoke();
_held = false;
}
void Click()
{
AudioManager.Instance.PlayUISound(ClickSound);
OnClick?.Invoke();
}
}
}