UI in gaming is all the visual elements on your screen that allows the player to interact with the game itself, essentially it’s how the game communicates information to the player and how the player responds to that information. It’s a two way street between the game and the player. (1.)
So these visual elements may include
UX/UI are similar but not the same, UI (User Interface) is what you see and interact with, whereas a UX (User Experience) is how it feels to use, An example I can think of is the Minecraft crafting table menu, whilst the UI looks great and matches the games aesthetic. How am I meant to know the crafting recipe? That creates a bad user experience, however Mojang came up with a good idea to include a green book beside the table’s UI which allows the user to see crafting recipes, a fun side note, when you discover a new ore or block, a notification will pop up to let you know that there are new recipes to craft.
The reason why UI is in games is to help the player understand what is happening in the game, take a health bar for example, its purpose is to let you the player know how close or far they are from losing in the game. Some other examples I can think of are objective markers which show the player where to go or what to collect.