How to update an EventTrigger script argument via code?
Hi, first Unity project and first question!
I have a game object in my scene that, when it receives a click event, will update text in several places. The text is all coming from a JSON array of objects. What I have so far is an UpdateText() function that takes an integer as argument, then fetches the corresponding text from json[integer], and updates the scene:
What I'd like to be able to do is, once the text has been set, update the integer argument within the script to be something else, but I can't figure out how to get at that data. I've been trying with this.gameObject.GetComponent<EventTrigger>()
, but haven't been able to pull anything useful from it, and would love any advice on getting hold of it!
I found this interesting and also looked around. bottom line, it seems not possible.one can add and remove those persistent listeners but can only edit their content in the inspector. just a different approach idea.ins$$anonymous$$d of using an EventTrigger, create a class, implement the IPointerClickHandler interface and attach it to the gameobject ins$$anonymous$$d. this way you can react to the click but control what is passed to whom, eg control the int and then call UpdateText from there.
Your answer
Follow this Question
Related Questions
Event on mouse up 2 Answers
How to make an event when 2 UI Image touching ? 1 Answer
How to detect click events on overlapping UI elements? 1 Answer