Unity select Images and call method

Hi guys!
I am making a game in Unity and I want to be able to switch between images. I want the images to do something when I press a button on my controller/keyboard. Also it should be possible to switch between them when using the joystick. I put a button on the image which should make it possible. The switch already works as I give the navigation on the button certain values. When switching the selection I want to activate UI elements (another image) that surround the button but I don’t know how to do it. Do you guys have an idea?

Hi BigGuy, I’m not sure I understand the UI setup you’re trying to make. Are you using uGUI or UI Tollkit to set it up?

In any case you can set a Listener for the Click event and toggle the other elements on/off.
But how?

If you’re using UIToolkit, you can register a ClickCallback on any component, no need for it to be a button.

Other visual elements like the Toggle component have a Value property you can listen to for changes (you can see an example in the documentation).

Components in uGUI have similar behaviours but depend on the control itself.

Another aproach as it seems you have something going on already, is to use Delegates. Delegates work somehow as event listeners but for methods. Let’s say you already have your controller calling a method when the player presses a button, you can set a delegate for that method which will start other methods (in other scripts if needed) each time it gets called. You can learn more about delegates on Unity Learn.

If you could give us a more detailed description, a piece of code or a screenshot to illustrate what you are trying to acomplish maybe we could give you a more concise answer.

Hope this helps.
Happy coding.