Each button is a prefab. My question is what is the best way to listen for button events. I just don’t want to assign events to all buttons every time. I don’t know exactly what the best approach to this problem is.
But in the end I’d like to have something similar to:
this.keyboardNode.on(‘input’, (key) => {
// Do something
});
Does anyone have any ideas on how best to implement this?
There is no other way than binding the touch event to every button.
But you can do it quickly by looping through children of the buttons’ parent node. Something like
For some reason it doesn’t work. I tried to use your example with the same node structure as yours.
I use Cocos Creator 3.8.1 (Maybe this is the reason?)