Book Image

Hands-On Unity 2021 Game Development - Second Edition

By : Nicolas Alejandro Borromeo
Book Image

Hands-On Unity 2021 Game Development - Second Edition

By: Nicolas Alejandro Borromeo

Overview of this book

Learning how to use Unity is the quickest way to creating a full game, but that’s not all you can do with this simple, yet comprehensive suite of video game development tools – Unity is just as useful for creating AR/VR experiences, complex simulations, real-time realistic rendering, films, and practical games for training and education. Hands-On Unity 2021 Game Development outlines a practical journey to creating your first full game from the ground up, building it step-by-step and applying your knowledge as you progress. Complete with hands-on tutorials and projects, this easy-to-follow guide will teach you how to develop the game using several Unity tools. As you advance, you will learn how to use the Unity engine, create simple scripts using C#, integrate graphics, sound, and animations, and manipulate physics to create interesting mechanics for your game. You’ll be able to apply all the knowledge that you gain to a real-world game. Later chapters will show you how to code a simple AI agent to challenge the user and use profiling tools to ensure that the code runs efficiently. Finally, you'll work with Unity's AR tools to create AR experiences for 3D apps and games. By the end of this Unity book, you will have created a complete game and built a solid foundation in using a wide variety of Unity tools.
Table of Contents (29 chapters)
1
Section 1 – Our First Level
7
Section 2 – Improving Graphics and Sound
16
Section 3 – Scripting Level Interactivity with C#
24
Section 4 – Releasing Your Game

Creating a responsive UI

Nowadays, it is almost impossible to design a UI in a single resolution, and our target audience display devices can vary a lot. A PC has a variety of different kinds of monitors with different resolutions (such as 1080p and 4k) and aspect ratios (such as 16:9, 16:10, and ultra-wide), and the same goes for mobile devices. We need to prepare our UI to adapt to the most common displays, and Unity UI has the tools needed to do so.

In this section, we will explore the following UI responsiveness concepts:

  • Adapting object positions
  • Adapting object sizes

We are going to explore how the UI elements can adapt their position and size to different screen sizes using advanced features of the Canvas and RectTransform components, such as Anchors and Scalers.

Adapting object positions

Right now, if we play our game, we will see how the UI fits nicely onto our screen. But if, for some reason, we change the Game view size, we will see how objects...