- Home /
ExecuteEvents.Execute pass object to from ui
I have been looking around and i cannot figure out how to do this - What/how do i pass an object to (where it says Button.gameObject right now);
if (checkani) {
var pointer = new PointerEventData(EventSystem.current);
ExecuteEvents.Execute (Button.gameObject, pointer, ExecuteEvents.submitHandler);
}
When the button I want to click is part of the Ui? how to pass a UI button to this code.
Answer by HTwist · May 20, 2015 at 01:05 AM
If you want to pass the button from the inspector, you need to create a public property in your monoBehaviour public Button Button;
and don't forget to add the UnityEngine.UI namespace.
After that you should be able to assign it from the inspector.
as in I should be able to drag my Ui buttons from the hierarchy to a slot on the gameobject that has this script?
You are missing the namespace. At the top of your file add Using UnityEngine.UI;
now I can assign it and don't get any errors,¨XD
but when I play the game, even if i get my object on top of the button and clicks the sequence of buttons that make checkani true the button doesn't react?
Your answer
Follow this Question
Related Questions
ExecuteEvents with uGui slider 1 Answer
Example of setting up a button OnClick event via scripting? 2 Answers
Multiple Cars not working 1 Answer
When does Drop UI event get called? 0 Answers
Issues when hooking GUI to code 0 Answers