Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Farflame |
I have 31 TextureRects on a larger TextureRect, set manually in a 6 * 5 grid, plus a spare one. All I need to do is to have them respond when the mouse is clicked on them by telling the main script which one they are. Since they’re all identical in every other way and need to behave the same, they can all just use the same node signal (gui_input). But I can’t work out an efficient way that the signal would identify which one was clicked if they all just report back to the same script.
All I can think of is to set each signal manually and then jump to a function from there, but that would mean 31 of this…
func _on_1_gui_input(event):
CheckClick(event,"1")
func _on_2_gui_input(event):
CheckClick(event,"2")
func CheckClick(event, num):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
# DO STUFF
Obviously this just goes against every rule of programming efficiently. There must be a simple way of doing this, either through groups or from the parent or something, but I’m being tired and dumb right now and can’t think of the solution.