Changing values in another class with a UI button

I’m an artist trying to branch out into coding and game design. i’ve been trying to find more learning materials on UI Toolkit and linking it to existing code. Every article/tutorial seems to deal with adding editor UI elements, or how to build the visual part of the UI.

I’m really struggling to find tutorials and code examples on how to write the C# code to link say a button in a menu to a bool in my game manager. I see quite a few examples showing how to create callbacks so you can display a variable in the UI. that’s great for health or something like ammo left ( i may even re-write my drawpile and discard pile code to use that) but the lack of examples is really hurting. I tried reading the Unity manual on the UI Toolkit.

Can anyone point me to some good learning resources on the UI Toolkit or just some good code examples on how to make the UI interact with your game and not just display variables on screen?

This is less - or not even - a UI question but a general coding and architectural question. The correct question isn’t “How do I get a button to alter a value in my game manager?” but “How do I globally access my game manager?”

Look at patterns like the singleton pattern, or other ones such as the Event Broker or Pub/Sub pattern. These are common methods for providing decoupled messaging between two or more components - all of which are agnostic to whether you’re working in UI or not.

Thanksfor the info, that’s what i thought but i was trying to have the button change a bool, then have the update function in my game manager check the bool in update. that wasn’t working for some reason, something wrong with my update function i guess. Having it call the change state function in my gamemanager directly worked though. I can finally check the main menu off my prototype list.

how do i mark the thread as solved?