Creating a 3d game for android unity. Creating a game on Android. What is a game designer

Developing games for Android OS devices requires an approach similar to developing for iOS. On the other hand, the hardware of Android devices is not subject to clear standards, which makes it necessary to solve issues that are absent when working with iOS. There are also differences between the Android and iOS versions of Unity.

Preparing the Android Development Environment

Before you can test your games on the device, you will need to prepare your development environment. In particular, download and install the Android SDK of the desired platform and add your device to the system (this process is different for Windows and Mac). This is written in detail on the Android Developers website, as well as Additional information may be provided by your device manufacturer. Since this is a rather complicated process, we have prepared a small instruction that will help you prepare everything you need for development. If you need more information, you can get it from the Android Developer Portal.

Access to Android features

Unity provides an API for accessing Android input and settings. The available classes are documented on the Code for Android Assemblies page.

Linking C, C++ or Java code to scripts

Unity allows you to call functions written in C/C++ directly from scripts (Java functions can be called indirectly). To learn how to access functions from native code from Unity, visit the Android plugin building page.

Occlusion Culling (clipping invisible geometry)

Unity provides support for occlusion culling, which is very useful when optimizing for mobile platforms. More information can be found on the Occlusion culling page.

Customizing the startup screen

The splash screen displayed when the game starts can be customized - see this page for more information.

Troubleshooting and Error Reporting

There are many reasons why your app is crashing or not working properly. Our guide to solving Android-specific problems will help you deal with the causes of errors in the shortest possible time. If, after reading the manual, you assume that the problem is in Unity, you should file a bug report. Refer to this page for instructions.

How Unity for Android differs from the desktop version

JavaScript with strong typing

To improve performance in the Android version of Unity, dynamic typing in JavaScript is always disabled (as if #pragma strict were automatically applied to each script). This is important to remember if you are porting a project to Android from older platforms, and if you encounter compilation errors, the problem should be looked for first of all in typing. Such errors are usually easy to deal with by making sure that the types of all variables are explicitly specified or cast during initialization.

While Unity Android supports DXT/PVRTC/ATC textures, Unity will decompress textures to RGB(A) format on runtime if these compression methods are not supported on the specific device. This can seriously affect GPU rendering performance, so it is recommended to use the ETC format. It is the de facto standard for Android and should be supported by all modern devices. On the other hand, ETC does not support an alpha channel, and sometimes 16-bit RGBA textures will be the best choice in terms of quality, size, and rendering speed where an alpha channel is needed.

Unity 3D will be an indispensable tool for those who professionally approach the task of creating high-quality material. The application integrates ready-made models, scripts and textures, which can be supplemented with your own content - images, sounds and videos.

Finished products created in Unity 3D are compatible with almost all popular platforms - ranging from mobile phones and ending with SMART TVs.

Program features:

  • learning engine Unity;
  • flexible multifunctional editor;
  • high compilation speed;
  • easy-to-learn interface;
  • compatibility with a large number of platforms.

Principle of operation

To use the program, you need to download the Unity Hub platform, and through it you can try out the features of the free Personal version. It is available with monetization volumes up to 100 thousand dollars annually.

In addition to the Free version, you can subscribe to two other advanced versions:

Unity Plus (~$25 monthly) - provides limited access to the Customer Success Advisor service, collects information about failures on user devices, monitors feedback.

Unity Pro (~$125 monthly) is the maximum subscription option. Provides support from professional developers, allows you to get priority access to support from the creators of the program, includes improved capabilities for monitoring performance and collecting statistics.

Building all game actions is based on a sufficiently high-quality physical core of the program (PhysX), on which the behavior of the models depends. Thanks to the ability to import textures and objects, you can make the product unique or use the tools integrated by the developer. It is important to understand that each object created in this constructor is a specific set of scripts and events that you can control yourself.

To work professionally with Unity 3D, you need some time to get acquainted with the interface and features of the application. To do this, you can find a lot of videos on the Internet or visit specialized courses that are held in many large cities.

It should be noted that in order to work with 3D graphics, you need to have a modern computer with a hardware video card.

Pros:

  • almost limitless functionality for creating projects;
  • support for browser-based 3D graphics;
  • compatible with game consoles and modern TVs;
  • a large number of visualization tools;
  • there is a free version.

Minuses:

  • specific knowledge is needed to create a quality product;
  • there is no possibility of very fine tuning of the physical core of the program;
  • there is no translation of the interface into Russian.

You can download Unity 3D not only to prepare a competitor to the popular online toy Juggernaut (which is also drawn with the tools of the hero of our review), but also to create chic 3D presentations. Let it take a little longer, but the wow effect for the audience is guaranteed.

To get acquainted with the capabilities of the platform, just download free version Unity 3D. If you need access to the source code, look towards paid versions.

Analogues:

  • game editor- free app to create games;
  • Construct 2 is a popular game constructor with a simple interface.
  • Construct 2 is a powerful program for creating 2D projects.

Hi all! Having learned how to make games on this engine, I want to teach you the same. First, we need Unity3d itself, any 3D model editor and straight arms growing from the shoulders.

1. Learning the program

For starters, I recommend installing Monodevelop! Let's understand what Unity is. Unity is a multi-platform game development environment. It is because of its simplicity and understandability that every third person has made games on it at least once.

Consider the screenshot above:

  • The stage is your creative sandbox.
  • Project - here are all the animations and models, sounds and textures.
  • To install models in the top toolbar, select Assets-Import New Asset. You can also Assets-Import Package-Custom Package. In the second case, the package must be in the .unity extension.
  • Hierarchy - all objects in the scene. There you create parents for the object. Just move an object to another in the hierarchy menu, and it will be attached. The result will be a kind of folder.
  • Toolbar - list of tools. There you can enable 2D,3D mode.
  • Inspector - a feature of an object, where you add animations, scripts and more. There you can use the tools: move the camera, move the object, stretch, rotate the object.


Now you see the object menu in it you can add animation, scripts and more.

I think that with this menu you will not have problems.
Click to create any object.

In general, we have studied the program, soon it will be possible to write our own games.

2. Create a simple game

First, let's create a Create-Terrain territory. Add grass and trees. By clicking on the ground on the right, a window will appear, select trees, grass.


Also create mountains and bumps. Then load the Characher controller pack into the project. Then we search in the window with the Standard assets-Characters controller project and select the first-person view (capsule) or third-person view (mechanic).
If the first person, then just put it on the ground. If from the third, then you need to download the animation. I also recommend setting the scene lighting to Create-Directional Light.


To add music, drag it to the desired item.
The game is ready, but how to compile it?

To do this, go to File-Build settings-player settings (for label and name). Choose a platform and voila, you're done. To do this, you need to install the Android SDK. But there you need to specify the folder with the SDK, and you need not just the SDK, but the API of the desired level (for example, Android 4.2 has API 17). For example, in order for the game to be on Android 4.0+, you need to install these APIs.

In the next article, I will tell you how to set up controls for Android or iOS and learn how to write scripts yourself.

Development mobile applications is one of the most profitable occupations in the computer industry. Creating an Android game costs hundreds or thousands of dollars, and the profit can reach up to a million dollars. In this regard, many people are interested in developing applications for the phone. In this article, you will learn how to create an Android game from scratch using a computer, which engine and designer is better to choose.

None successful game can't do without beautiful graphics Therefore, the creation of design is one of the most important stages of development. Design on the Android OS is implemented using a “design document” or design document. You need to start creating a toy with its detailed study. The file contains:

  1. Object models;
  2. Functional specifications;
  3. Game content;
  4. Interface.

Let's consider each of the points in more detail.

Object models

This is information about the functionality of each item. Object models are responsible for the ability to buy and sell items, as well as for improving the game characteristics of characters.

Functional specifications

It describes the gameplay, the main features of each character. Also here is a description of the features of game items - weapons, first aid kits, armor and others. Essentially, functional specifications are the rules by which game process. The better this section is worked out, the easier it will be to create a high-quality Android game.

Game content

This is the text filling of the game. It describes the dialogues of the characters and what weapons can be used to deal damage, how much health a hit will take, what characteristics will increase when using various equipment. It also contains detailed description each item.

Interface

The interface is how the user will interact with the game. It includes buttons with which you can control the character, and menu sections: for example, play, score, settings, top players, help. If you have no experience in creating Android applications, before creating your own, download from the Play Market and analyze popular games and transfer the best solutions to your project.

Game engine

The core of any game is the engine. This is software that allows you to develop and run it. It contains a whole range of programs, including a rendering engine, a physics engine, sound, animation, and much more. To facilitate the process of writing programs, third-party developers create their own game engines specifically for Android applications.

Each of them offers different features: some are designed for 3D, others for 2D, multi-platform can be supported. There are a huge number of such engines, but if you are a beginner, it is better to choose one of the most popular ones, since all the necessary functions will be present there.

UDK

Torque 2d/3d

What is a game designer?

Constructor is a program that combines a game engine and an integrated development environment. The constructor makes the development process accessible to people who do not have programming skills. Some of the designers allow you to create games of certain genres, others have maximum functionality, but cost much more money. For a novice creator of mobile applications, the choice of a designer is one of the most crucial moments, because the fate of the future application will depend on its capabilities.

The constructor allows you to create games of various genres for Windows, Android and iOS. Offers big choice ready-made locations, objects, characters and sound design, so the creation of the first Android game will not take much time. Users familiar with the JS and C++ programming languages ​​can use the embedded GML. The only drawback is that the program is not translated into Russian.

Conclusion

Creating an Android game is not an easy, but very profitable business. If you decide to develop a game and make money on it, first work out the idea. Next, write a “design document” and decide on a game engine that can maximize its potential. After that, you can proceed directly to creating the application in the constructor.

Video

To learn more about the process of creating Android games, check out a series of videos dedicated to this activity.

How to quickly and relatively easily create a simple game or application for Android? Read about this in the article below, which deals with working with the Unity3D engine.

Do you play computer games? If so, then, for sure, in the process of passing the next game blockbuster, you sometimes had thoughts like: "But here, I would have done it wrong!". Do you want to be a developer yourself? Then, I offer you a small, but very entertaining "adventure";)

What is an engine and why is it needed?

Previously, back in the days of the first computers, games and programs were created by the so-called "hardcore" method. That is, for a full-fledged development, it was required to be a fairly experienced programmer who thoroughly knows his programming language and can write almost the entire game (including pixel graphics and special effects!) in a simple Notepad. There were few such people and they were highly valued (and are still valued) ...

Today, the threshold for entering the topic of programming has decreased significantly. And this is facilitated not only by the availability of literature and all kinds of training materials, but also by the increasingly simplified development process. Nowadays, it is rare to meet real "hardcore" people, since quite convenient development environments have appeared, which are called "engines".

The essence of the engine is that it allows you to import all the necessary game objects in a simplified visual mode, arrange them on a virtual stage and configure all their parameters. That is, the task of the programmer is only to write the game logic correctly!

However, you have to pay for the convenience of work with a slight increase in the size of the project (sometimes even several times!) in comparison with its counterpart, written in the old "hardcore" way. It is for this reason that some developers do not like engines or try to write their own, in which only the components they need are used ...

But you and I are far from true programmers :) Therefore, let's create a simple game for Android based on the popular and powerful Unity3D engine.

Getting started with a project in Unity3D

So, why did we decide to use Unity3D:

  • the ability to create full-fledged 2D and 3D games;
  • the ability to compile the finished game for any device;
  • relative ease of control of the engine;
  • good extensibility of functionality by connecting plugins;
  • relatively small size of the final assembly of the game (compared to other engines).

The main trump card of Unity3D, of course, is its versatility and multiplatform. Finished game(perhaps with a little tweaking) You can port to PC (Windows, Linux or MacOS), Android, PlayStation or XBox! To do this, we need to download only the engine itself, which, by the way, "weighs" more than a gigabyte and the necessary SDKs (if development is planned for mobile platforms or console). If you want to make a game for Windows, then you do not need to download anything, but since we are going to make a game for Android, we will also need to download the Android SDK (Software Development Kit). I advise you to download the SDK in a ZIP archive for greater convenience of working with it.

When everything is downloaded, you can unpack to any Android SDK folder that is convenient for you, and then proceed to install Unity3D itself. It is installed like any regular Windows program, so there should be no problems with installation. After installation, the engine will start and we will first need to create a new project:

To do this, we will need to close all welcome and introductory windows, and then select "New Project" from the "File" menu. In the window that opens (see the screenshot above), we will be prompted to specify the project save folder (its name will be the same as the project name), import some standard sets of functions (we do not need them) and specify the operating mode. Select 2D as the mode and click the "Create" button. This completes the preparatory part of the work :)

Engine interface and project hierarchy

After creating the project, it will be loaded into the Unity3D workspace:

This workspace itself has a modular structure and consists of several nested windows that can be moved around as you like. I have it set up like this (from left to right and top to bottom):

  1. Hierarchy window - displays the hierarchical position of active and inactive objects on the scene. By default, the only object immediately in the list is the Main Camera.
  2. Scene window - displays the entire game scene and objects on it (including cameras, sounds, textures, etc.).
  3. Inspector window - displays all the properties of the object selected in the hierarchy or on the stage and allows you to edit, supplement or delete them.
  4. Game window - displays the game world that is visible to the camera and allows you to select the size of the virtual game test window in pixels. Also, allows you to activate the expansion of the game window in full size (Maximize on Play) and enable / disable the display of various information for the developer.
  5. Project and Console windows. The Project window is used to navigate through project resources: uploaded images, sounds, models, and so on. Also by means of this window (context menu) you can create new empty game objects of different types and scripts. The Console window is used to display error messages (red), warnings (yellow) and various debugging information requested by you (gray).
  6. The Assets Label window is the lower part of the inspector window, which displays a preview of the object or file selected in the Project window.

In addition to all of the above, pay attention to the three buttons at the top center. They allow you to start your project, pause it (sometimes useful when debugging to see what is being done in the Hierarchy, for example) and, accordingly, turn it off.

We will create a simulator of a musical instrument: Indian folk drums called "tabla", therefore, to get started, we will create two empty folders in the project in which sounds and pictures will be stored. You can create a new folder by calling the context menu in the Project Navigator window and selecting the "Folder" item from the "Create" list.

Here it is worth saying a few words about how these folders should be named. For a simple game, like our simulator, in principle, the folders can be "named" as you like, however, there are at least two names that are better not to use, since they are reserved by the engine. These are the names Resources and Plugins. In large projects, the Resources folder is created immediately and all game "spare parts" (pictures, sounds, models, textures and prefabs) are already stored in it (sorted by subfolders). In Plugins, as the name implies, all additional third-party sets of functions (the so-called "assets" (assets)) are stored, of which there are quite a few on the Asset Store - a store for extensions for Unity3D.

Importing Files and Creating Game Objects

Before creating a new game project it is desirable to prepare in advance all the files necessary for its operation. In our case, these files are pictures and sounds. The easiest way to import them into a project is to simply drag and drop them into the desired folder. Let's start with pictures...

After the images appear in our Images folder, they need to be tweaked a bit:

The fact is that by default Unity3D compresses all images added to the project with loss of quality. If we do not need such a loss (especially true for games with HD graphics), then we should select each image and in the Inspector window change the value of the "Format" parameter from "Compressed" to "Truecolor" in the "Default" tab. You may also need to change the "Max Size" parameter if it is smaller than the actual image width (default is 1024 pixels). After all the changes, you need to remember to click the "Apply" button to apply them. If necessary, we perform similar actions for all other images.

Now, let's create game objects from our pictures. To do this, simply drag the desired image into the Hierarchy window. The picture or 3D model will be automatically converted into a Game Object and displayed at the starting coordinate point in front of the camera.

First of all, we added a background image, which should be displayed in full screen. You can check whether this is so by selecting a camera in the hierarchy window and looking at how its frame is displayed. In the screenshot above, you can see that part of our background remains outside the camera's view, so we need to adjust the size of this view by dragging the frame directly on the stage or by editing the "Size" parameter in the Inspector window. In our case, we had to change the default value (5) to 5.4.

That's it, we don't touch the camera anymore, but add and adjust the rest of the pictures. When adding, we see that some of them are too big for our game. You can reduce them either physically in a graphics editor, or by means of the engine. Let's try the last method. To do this, select the image in the Hierarchy window, and in the Inspector window change the "Scale" values ​​for the X and Y coordinates from 1 to 0.5 (that is, reduce by half). In the same place, it is desirable, in order to avoid overlaps, to assign to all game objects (except for the background) a non-zero order of layers (Order in Layer):

The last step in preparing game objects from pictures will be "hanging" colliders on them. In Unity3D, colliders are used as interaction detectors between objects. That is, in fact, a virtual shell is put on our picture, which can register touches to it.

To add a collider to an object, select it in the Hierarchy window, and then click the "Add Component" button in the Inspector window. In the list of components that appears, we are looking for Physics 2D (ordinary 3D physics will not work in our mode) and out of all the options, "Circle Collider 2D" is the most suitable for us. We choose him. A green stroke will appear around our object, which displays the borders of the collider. It remains only to check the "Is Trigger" checkbox so that our collider only registers clicks and no longer interacts with the surrounding game space:

Similar actions are repeated for all remaining objects. Only our background will differ from other objects. For this, we'll apply a Box Collider 2D and set the Position Z to be greater than zero to push the collider and the background itself into the background (we'll need this later).

Working with sound

With sound in Unity 3D, at first glance, everything is somewhat confusing. But, let's try to figure it out in order :)

First of all, we need to drag all the sounds into the Sounds folder and tweak them a little too:

If the volume level of all your sounds is initially adjusted, then all you need to do is turn off 3D sound processing. In 3D games, this processing is needed in order to simulate the approach of the sound source when the camera approaches it. But in 2D we don't need this, so we select each sound in turn and uncheck "3D Sound" from it.

Now we can start adding sounds to game objects. To do this, we need to select each button in turn and add a new "Audio Source" component to it from the "Audio" section. When the component is added, select the corresponding "Audio Clip" button and uncheck the "Play On Awake" checkbox active by default (play when it appears):

When all the sounds are attached to the right buttons, it's time for the fun part - scripting...

First script

Before starting to parse our first script, it is probably worth saying a few words about the scripting system in Unity 3D itself.

Unity allows you to write code in three languages ​​at once: JavaScript (more precisely, its slightly modified version of UnityScript), C # and Boo. In a number of books and guides, you can find the opinion that for beginners, scripting in Unity is easier to master using JavaScript as an example. However, this language is not as comfortable as the others, and in the future you will most likely have to relearn. Therefore, it is better to start immediately by learning C # (Boo is also good, but there are few training materials on it).

Now about where to write the code. The default code editor in Unity 3D is the MonoDevelop IDE. The advantage of this development environment is that it has hints for quickly entering standard methods, classes, and functions, as well as a syntax checking system. However, for me, the disadvantage was the bulkiness and high resource intensity. Fortunately, in the Unity settings you can set anything as a text editor, so I "hung" the lightweight and functional Notepad ++ for myself (almost all examples will be shown in it).

And the last. Naturally, without reference materials in mastering all the intricacies of the engine, you will not go far, so here is a list of several sensible Internet resources on the topic of Unity 3D:

  • http://docs.unity3d.com/ru/current/Manual/UnityManualRestructured.html - official manual for the engine with partial translation into Russian (appeared recently and is sometimes unstable);
  • http://docs.unity3d.com/ru/current/ScriptReference/index.html - official scripting reference manual in English;
  • http://unity3d.ru/distribution/index.php - Russian forum for Unity 3D developers;
  • http://habrahabr.ru/post/141362/ - a series of lessons on creating three-dimensional games on Habrahabr;
  • http://msdn.microsoft.com/ru-ru/library/618ayhy6.aspx - Microsoft's official C# reference in Russian.

Well, in order not to drag it out for a long time, I propose to immediately create the first script. Under scripts, if there are a lot of them, it is better to allocate a separate folder, but our game will be simple, so we can create a script directly in the root folder of the project. To do this, call the context menu in the Project window, select the Create list and click "C# Script". Let's name our new script, for example, Sounds and open it with a double click. Having removed the standard methods Update and Start, and then, having registered the necessary ones, we get the following script:

If you have not reconfigured the editor, then our script will open in MonoDevelop. Let's take a look at its structure...

In fact, every C# script consists of three main parts:

  1. At the very top, the libraries that need to be connected for the script to work are listed (for example, "using Unity.Engine" connects the work of the engine itself, and "using System.Collections" - a library containing a number of built-in classes for the script to work under different systems).
  2. Class and variable declaration. There is no concept of a script in C# as such. Instead, the concept of a "class" is used, which includes a number of methods and functions. Although, in fact, in the context of Unity 3D, this is almost the same thing :) The main thing to remember is that the class name must match the name that we gave the script. The peculiarity of variables in C# is that they must (except for temporary ones, which are declared in the script itself) be typed. In practice, this means that the access level (private or public) and type (int, float, bool or, as we have in the script, AudioClip) must be specified for the variable. At the same time, any variable name can be given. Or you can immediately give it a value ascribe.
  3. A set of methods and functions. A method in C# is almost any function that performs certain actions. In principle, in the literature on Unity 3D they are called functions, but if we are talking about C # as a separate programming language, then these are, after all, methods :). Pure functions in Unity are, for example, standard functions for outputting sound, drawing GUI elements, etc., which are used inside methods.

Knowing now the structure of the script, it is easy to understand its meaning, which boils down to the following... In the Sounds class (script), we declare 9 variables of the AudioClip type with the names we need for the convenience of distinguishing them. We make them necessarily public (private ones will not be displayed in the editor, and we will need to "hang" sounds on them through the editor). And then in the body of the script we use the standard method "void OnMouseDown ()". Previously, it was responsible only for processing a mouse click, but in new versions it is also interpreted as a touch to the touch screen. In it we write the conditions by which we check the names of the pressed colliders and, if we detect a press of one of them, we output the corresponding sound (we use the standard audio.PlayOneShot(); function).

When writing code, be careful to include all opening and closing brackets, otherwise you will constantly receive error reports in the Console and will not be able to run your project at all! Also pay attention to the use of capital letters in the names of methods and functions. They are also often the cause of errors. And, of course, observe all signs (periods, colons and brackets), in short, the syntax of the language. At first it will be difficult, but over time you will start writing from scratch without mistakes!

When the script is ready, select it and in the Inspector window assign a different sound to each variable. Now we just have to apply our script to the objects in the scene. The easiest way to do this, again, is by dragging the script directly onto the desired game object in the Hierarchy list:

If the script was dragged correctly, then it should appear in the Inspector window next to the object on which we dragged it. Accordingly, we drag the script to all the objects that should sound in the game and we can try to run it. When you click on our game buttons, now, finally, the specified sound will sound!

Introduction to GUI

In principle, the Game is already functioning with us, but somehow it is too "bald". Something is missing in it ... Or, at least, an inscription with the name that is in front of us! In other words, you need to implement some kind of intelligible user interface.

Actually, GUI is an abbreviation for English. "Graphical User Interface", that is, a graphical user interface. Traditionally, it includes such components as:

  • buttons;
  • window;
  • text areas;
  • checkboxes and/or radio buttons;
  • sliders (scroll bars), etc.

In Unity 3D All this (and even something more than that) is fully present. The main thing is to learn how to use it! Let's take a look at how Unity's GUI can make a simple heading.

To do this, create a new script named Interface and modify it as follows:

Consider carefully the script in the screenshot. Here we write only one public variable of the GUIStyle type, which is new for us. This type allows you to visually change the appearance of the elements to which this style is assigned. Styles are useful when there are many interface elements of the same type (for example, buttons), but they should have a different look.

Next, we create a button ("GUI.Button"), which has the following syntax: condition - 4 coordinates (horizontal indent from the left edge, vertical indent from the top edge, width, height) - visible text in quotes and further, optionally, style indication. The necessary functions are written inside the button condition. In our case, we registered the transition to the developers' site ("Application.OpenURL("");").

GUI scripts can work from any game objects, but usually they are advised to "hang" them on the camera, which we will do by dragging the script onto the Main Camera object. Now, if we select it in the Hierarchy window, then in the Inspector window we will be able to see the public variable of our style, by expanding it, we will get full access to the settings of this style!

We can specify the text color and texture for the background in any situation (for the button, you need to register its three options (Normal - normal view, Hover - on hover and Active - on click), set padding and adjust the font. By default, the only one available in Unity 3D the font is Arial, however, you can manually load any other font into the project and apply it in the "Font" field, setting all related parameters.

What is interesting and at the same time not very convenient is that the GUI elements are not displayed on the stage until we start the project, so adjusting the parameters of each element can take a lot of time. Let's run the project and see what our button created above will look like:

Changing the interface by condition and static variables

We have already done a lot, but there is always room for improvement :) Therefore, I propose, as a last example, to create a help window, with which normal developers usually supply their games and applications. To do this, add a picture for such a button in the form of a question mark to the folder with images and make a game object out of it. Let's hang a collider on it and write a script with a name, for example, "Help" with the following content:

In this script, we have two variables. The first variable defines the skin that will be used for all interface elements described in this class. Unlike styles, which we discussed above, skins allow you to change the appearance of not only the individual element to which they are assigned, but all elements of a certain type at once. In addition, unlike styles, skins are not assigned to elements, but are declared immediately for the entire method and work until another skin is declared. You should also remember that skins exist not only as variables, but also as separate files. Therefore, before declaring a skin, you must immediately create it in the "Project" window from the context menu: "Create" - "GUI Skin".

The second variable we have is a logical (or otherwise Boolean). It can only have two values: "true" (true) or "false" (false). Due to its binary nature, such a variable is perfect for implementing all kinds of switches. In our case, it will be responsible for displaying the text describing our game.

However, if you look closely, you will notice that the last variable has one wonderful parameter - "static". Adding this parameter to variables allows you to make them static and access them from other scripts!

But back to the rest of the code. The "void OnMouseDown()" method already familiar to us here will serve as a switch for the "isVisible" variable using a simple condition. However, after the condition there is another function. This function ("Debug.Log();") is used to output "on the fly" to the Console the values ​​of the variables we need (we enter them without quotes in brackets). As you can see, inside a function, you can combine both immutable text (written in quotes) and variables (without quotes). The main thing is that there should be a "+" sign between all the data.

Further in the text of the script, we have a method for drawing the interface ("void OnGUI()()"), inside which we see the declaration of a new skin ("GUI.skin = HelpSkin;") and a new interface element of the GUI.Box type. Unlike a button, a box is an inactive element and usually serves to display various text or graphic data.

Pay attention to how we set the positioning for the box. Here, all values ​​are not specified directly, but with the help of mathematical expressions, which, in fact, is an analogue of "fluid layout" in web development. The problem is that when specifying the exact sizes of GUI elements at different screen resolutions, they will not adapt and may be either too small or, conversely, large. In the next version of the engine, the developers promise to make the GUI adaptive, but so far we have to pervert :(

The last step on the road to success will be customizing our skin. We specify the skin file in the script variable, and then select this file in the project window. As with other files, skin settings will be displayed in the Inspector window. Here we are looking for the element that is subject to change (in our case, Box), open it and set it up in the same way as the style discussed above:

To see if our script works correctly, let's run the project and try to click on the help button:

Now everything works, but it is not always convenient to press the help button to hide the description back. It is more customary to poke any notifications into any free place than aiming at the buttons. And this is where we just need to use the fact that we made the "isVisible" variable static, as well as the collider hung on the background image...

Let's go back to our very first script ("Sounds"), which tracked button presses to play sounds. It will be enough for us to write only one line into it (more precisely, inside the "void OnMouseDown ()" method:

if (this.name != "HelpButton")(Help.isVisible = false;)

With this line we set a condition: if the name of the pressed collider does not equal the name of the help button, then the "isVisible" variable in the "Help" script will equal "false". Only it is necessary that the variable "isVisible" definitely has the postscript "static", otherwise we will get an error.

Now, at startup, we will see that our help window is closed when not only clicking on the button in the upper right corner, but also when touching any free part of the screen. The only thing that can be improved is to make the window hide when you click on it... This will be your "homework";) I can only say that the GUI box will need to be changed to a similarly designed button, again, with the setting skin and prescribing a function that changes the "isVisible" variable. Everything, keep quiet :)

Compiling the game and saving the project

Finally, everything works for us! This means it's time to save our game and test it on a real device. And for this, it needs to be compiled into an executable file (for Windows, for example, in EXE, and for Android, in APK).

If you want to compile a game for PC, then you don't have to make any preliminary settings. However, for Android, you will first need to connect the Android SDK we downloaded at the very beginning. This is done quite simply: go to the "Edit" menu, call the "Preferences" item and in the window that opens, go to the "External Tools" tab. Here we are looking for the line "Android SDK Location" and in it we indicate the path to the unpacked archive with the SDK (see the screenshot below). By the way, here you can also change the monstrous MonoDevelop text editor active by default to your favorite one :)

And now the moment of truth has come! Go to the "File" menu and look for the "Build Settings" item there. In the window that opens, we will need to immediately add scenes for the assembly. If there is only one scene (as in our project), then it will be enough to click the "Add Current" button. If there are several of them, then you will need to open each of them and add them to the list of scenes in the same way, and then, by dragging and dropping, adjust their desired order:

The next step is to select the build platform (we are planning a game for Android, which means we choose it) and click the "Player Settings" button below. The Inspector window will open a number of settings, some of which are mandatory or highly desirable. It is desirable to indicate the names of the developer company, the program and its icon (Company Name, Product Name and Default Icon, respectively) at the top of the settings list.

At the bottom, in the "Other Settings" section, there are two required parameters: "Bundle Identifier" and "Bundle Version". The default version is set as 1.0, but the identifier will have to be created manually and, preferably, unique. It should consist of three parts, separated from each other by dots: the reserved word "com", then the name of the developer company, and at the end the name of the application itself.

You can change the rest of the assembly settings at your discretion or not change at all. The main thing is that now the compilation will already be able to start. To do this, just click the "Build" button in the "Build Settings" window and wait until the program gives us a ready-made application packaged in an APK file :)

Conclusion

This concludes our lesson-review on creating the simplest applications for Android. So that you can repeat everything we talked about, at the end of the article I will give a link to the archive, which will store all the resources of the game as a separate folder (if you want to do everything from scratch) and as a file with the unitypackage extension. The latter allows you to import the entire project into Unity at once, including dependencies, etc.

To import our project (and, by the way, any plugins downloaded from the Internet or the Assets Store), you need to go to the "Assets" menu, select the "Import Package" item, and in it "Custom Packege", then specify the path to our file and press the "Import" button. By the way, you can make a full backup of your project, saving it in such a unitypackage, from the same menu ("Assets") by clicking on the "Export Package" item.

It seems that everything :) As a person who himself mastered Unity 3D from scratch, in the article I tried to answer the maximum number of questions and highlight the main nuances of working with the engine that arise at first. But, perhaps, this will not be enough for someone, therefore, if you have any questions, you can contact me either directly by mail or on the forum: I will help you in any way I can!

I wish you all good luck and successful implementation of all projects!

P.S. It is allowed to freely copy and quote this article, provided that an open active link to the source is indicated and the authorship of Ruslan Tertyshny is preserved.