- Home /
Question by
DahmJaeger · Jul 23, 2019 at 03:37 AM ·
buttonclickpointeronmouseover
Simulate click OnMouseOver / OnPointerEnter
Hi, so I am trying to get a fake click from just hovering over a button. The idea is to have a cursor without real buttons, but when the player puts the pointer over a UI element, after a second it clicks it.
I don't know where to start, so any help would be very appreciated.
Thank you!
Comment
Answer by bpaynom · Jul 23, 2019 at 09:30 AM
So you need that 1 second after the OnMouseOver is triggered it clicks the button?
[SerializeField]
private Button theButton;
private bool over = false;
void OnMouseOver()
{
over = true;
StartCoroutine( _Click() );
}
void OnMouseExit()
{
over = false;
}
IEnumerator _Click()
{
yield return new WaitForSeconds( 1f );
if ( over )
theButton.onClick.Invoke();
}