- Home /
Assigning events on runtime
Hey there,
i have the following situation:
There are two gameobjects in my scene.
Moreover, i have two buttons (moveLeft and moveRight) in the canvas.
The goal is that i can move every gameobject for 60 seconds and than switch two next gameobject.
I assigned the EventTrigger´s throw the UI for the first gameobject and it works pretty well, i can move it left and right.
But.. what about the second gameobject?
Here is what i thought about:
Every 60 seconds i remove all EventTrigger´s from the buttons and assign the current one´s.
Question:
How can i add a listener for an "OnPointerDown" Event ?
You know any tutorials about this ?
Greetings and Thanks!
If I understand you right, you want to switch the gameobject your moveLeft and moveRight buttons apply to every 60 seconds? So why not change the variable that references the gameobject in the code of your button functions from the first gameobject to the second and then back, ins$$anonymous$$d of removing event triggers. Even if you need different code you could make an if condition in your button functions to say which implementation of the function you currently want. Another solution could be making two versions of your buttons and setting them active and inactive when you need to. Or am I understanding you wrong?
Your answer
Follow this Question
Related Questions
GameObject.Find breaks code with UnityEvent 2 Answers
Initiating a Drag event by code 1 Answer
OnDrag with Instantiated gameObject 1 Answer
How do I trigger an event (health loss) only once? 3 Answers