- Home /
How to to call a method from UI trigger event?
Hey,
I've created a UI prompt system for random in game choices, and a timer that selects one by default if not chosen.
It has 3 classes:
Prompt.cs (Handles UI creation basically)
Scenario_choices.cs (The base scenario class with some helper functions)
example_choice_script.cs (I create scripts which inherit from the base scenario_choices class)
Each prompt is a UI object that has an EventTrigger, and a method is assigned via script for OnPointerDown e.g. (text, type, method/function to invoke (OnPointerDown event)
This is called from my example_scenario.cs class:
public override void CreateUI(){
CreatePrompt("Square Prompt", "Square", HitSquare);
}
//Create prompt basically calls this in the base scenario class: new Prompt(txt, type, method);
This works fine when clicking the prompt, but I'm struggling to figure out how to call a method assigned to a specific prompt via script (C#) when a timer runs out. I'd like this to call from the base Scenario class if possible, as that's where the timer is.
I add the events here in the base prompt.cs class. So I believe the method should be attached to the prompt?
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener((data) => { myMethodName(); });
prompt_events.triggers.Add(entry);
Then I was hoping to call something like this, from my base scenario_choices class: failPrompt.eventTrigger.OnPointerDown();
But i'm not able to find anything that works.
Help would be awesome! Cheers
Your answer
Follow this Question
Related Questions
UI Buttons to work continuously when pressed and held for sometime 1 Answer
get object that uses the event trigger 1 Answer
Why Do My Obstacles Do This In My Object Pooler? 1 Answer
Pressing Button with Vive controller (Collider?) 0 Answers
variable not being changed outside of a method. [C#] 3 Answers