I’m currently working on creating a level select screen and the widget it uses, has a button per level (obviously, clicking a button opens the corresponding level). I’ve got it set up so that each of the buttons’ properties are dynamically added, such as Image. The widget also has a Border element wrapping the Canvas Panel so that I can apply an image to the background as well.
What I’m trying to do (which I can probably do manually) is change the background image dependent on which button has been hovered over. So for example, there are 3 buttons each with a screenshot of the level, ImageA, ImageB, ImageC respectively, when hovering over the first button, the BG should change to ImageA and when hovering over the second button it should change to ImageB. For this to happen I need to bind an OnHovered event to each of the buttons. While I can do this manually, if I have 100 levels, I’d have to bind 100 buttons.
First instinct was to loop through an array of my button refs and assign OnHovered to each one there but that just overwrites the reference of the previous binding so hovering over any of the buttons, will always reference the last one - Example.
Any help on getting this working would be appreciated.