It seems that in NGUI you can achieve what I want by sending a message:
SendMessage("OnClick");
(from: NGUI - Simulate a button press from script - Unity Answers)
I would like to do the same but with the new UI system in 4.6. Any ideas?
It seems that in NGUI you can achieve what I want by sending a message:
SendMessage("OnClick");
(from: NGUI - Simulate a button press from script - Unity Answers)
I would like to do the same but with the new UI system in 4.6. Any ideas?
Although this is not documented very well, currently you can send an event like this. (Not sure if it is the correct way to do this, but it seems to work)
ExecuteEvents.Execute<IPointerClickHandler>(gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.pointerClickHandler);
Then all Components that are IPointerClickHandler (like buttons) on the given gameobject will receive that event.
If you use this, then the Event will send the event to the first GameObject it can find that has a component with a IPointerClickHandler (Note that this goes only up in the hierarchy, so not to the children)
ExecuteEvents.Execute<IPointerClickHandler>(ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject), new PointerEventData(EventSystem.current), ExecuteEvents.pointerClickHandler);
That is basically everything I was able to find out about sending events yourself.
(Unity 4.6.0b20)