Showing and hiding pop-up menus with keypress

So far, we have made two panels that we plan on making pop-ups: Pause Panel from Chapter 2, Canvases, Panels, and Basic Layout and Inventory Panel from Chapter 3, Automatic Layouts. Right now they are both visible in the scene (even though Pause Panel is hidden behind the Inventory Panel). We want them to pop up when we press specific p and i on the keyboard. For demonstration purposes, we'll access the keyboard keys differently for each panel.

Remember that both of these panels have Canvas Group components on them. These components will allow us to easily access the panels' alpha, intractable, and blocks raycasts properties.

Get Mastering UI Development with Unity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.