I
I
IIICoder2020-03-06 10:13:08
Unity
IIICoder, 2020-03-06 10:13:08

How to programmatically click on a UI Button in Unity?

Hello. I ask for help from people who know Unity.
There is a UnityEngine.UIElements.Button button, to which I assigned several functions to the onClick event in the interface of the Button component.
When you click on the button, everything works fine, there are no problems. But I need to simulate pressing this button programmatically, from code.
Found a solution like myButton.gameObgect.GetComponent().onClick.Invoke() but it doesn't work. Compilation error (onClick has no such method). In the documentation, such a construction is described only for the old unit, but not for the version 2019.3 used.
How to programmatically click on a button?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-03-06
@freeExec

myButton.GetComponent<Button>().onClick.Invoke()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question