Schweitzer Fachinformationen
Wenn es um professionelles Wissen geht, ist Schweitzer Fachinformationen wegweisend. Kunden aus Recht und Beratung sowie Unternehmen, öffentliche Verwaltungen und Bibliotheken erhalten komplette Lösungen zum Beschaffen, Verwalten und Nutzen von digitalen und gedruckten Medien.
As we start on our journey of building mobile games using the Unity game engine, it's important that you are familiar with the engine itself before we dive into the specifics of building things for mobile platforms. Although there is a chance that you've already built a game and want to transition it to mobile, there will also be those of you who haven't touched Unity before or may not have used it in a long time. This chapter will act as an introduction to newcomers and a refresher for those coming back, and it will provide some best practices for those who are already familiar with Unity. While you may skip this chapter if you're already familiar with Unity, I think it's also a good idea to go through the project so that you know the thought processes behind why the project is made in the way that it is, so that you can keep it in mind for your own future titles.
In this chapter, we will build a 3D endless runner game in the same vein as Imangi Studios LLC's Temple Run series. In our case, we will have a player who will run continuously in a certain direction and dodge the obstacles that are in their way. We can also add additional features to the game easily, as the game will endlessly have new things added to it.
This chapter will be split into several topics. It will contain simple, step-by-step processes for you to follow. Here is an outline of our tasks:
This book utilizes Unity 2022.1.0b14 and Unity Hub 3.3.1, but the steps should work with minimal changes in future versions of the editor. If you would like to download the exact version used in this book, and there is a new version out, you can visit Unity's download archive at https://unity3d.com/get-unity/download/archive.
You can also find the system requirements for Unity at https://docs.unity3d.com/2022.1/Documentation/Manual/system-requirements.html in the Unity Editor system requirements section.
You can find the code files for this chapter on GitHub at https://github.com/PacktPublishing/Unity-2022-Mobile-Game-Development-3rd-Edition/tree/main/Chapter01.
Now that we have our goals in mind, let's start building our project:
Figure 1.1 - Creating a 3D project
Figure 1.2 - The Unity Editor
Figure 1.3 - The Layout button
We now have opened Unity for the first time and have the default layout displayed!
Tip
If this is your first time working with Unity, then I highly recommend that you read the Unity's interface section of the Unity Manual, which you can access at https://docs.unity3d.com/Manual/UsingTheEditor.html.
Now that we have Unity open, we can actually start building our project.
To get started, we'll build a player that will always move forward. Let's start with that now:
Figure 1.4 - Creating the ground
In Unity, by default, 1 unit of space is representative of 1 meter in real life. So, our Scale values will make the floor longer than it is wide (X and Z), and we have some size on the ground (Y), so the player will collide and land on it because we have a Box Collider component attached to it by default.
Note
The Box Collider component is added automatically when creating a Cube object and is required to have objects collide with it. For more information on the Box Collider component, check out https://docs.unity3d.com/Manual/class-BoxCollider.html.
Figure 1.5 - Positioning the player
This places the ball slightly above the ground and shifts it back to near the starting point. Note that the camera object (see the camera icon) is pointing toward the ball by default because it is positioned at (0, 1, -10).
Figure 1.6 - Current state of the game
As in the preceding screenshot, you should see the ball fall down onto the ground when we play the game.
You can disable/enable having the Game tab take up the entire screen when being played by clicking on the Maximize On Play button at the top, or by right-clicking on the Game tab and then selecting Maximize.
We now have the objects for both the floor and the player in the game and have told the player to react to physics! Next, we will add interactivity to the player through the use of code.
We want the player to move, so in order to do that, we will create our own piece of functionality in a script, effectively creating our own custom component in the process:
Dateiformat: ePUBKopierschutz: Adobe-DRM (Digital Rights Management)
Systemvoraussetzungen:
Das Dateiformat ePUB ist sehr gut für Romane und Sachbücher geeignet – also für „fließenden” Text ohne komplexes Layout. Bei E-Readern oder Smartphones passt sich der Zeilen- und Seitenumbruch automatisch den kleinen Displays an. Mit Adobe-DRM wird hier ein „harter” Kopierschutz verwendet. Wenn die notwendigen Voraussetzungen nicht vorliegen, können Sie das E-Book leider nicht öffnen. Daher müssen Sie bereits vor dem Download Ihre Lese-Hardware vorbereiten.Bitte beachten Sie: Wir empfehlen Ihnen unbedingt nach Installation der Lese-Software diese mit Ihrer persönlichen Adobe-ID zu autorisieren!
Weitere Informationen finden Sie in unserer E-Book Hilfe.