Working in Unity3d: the basics of creating games. Creating applications for Android Unity 3d games for Android

Unity 3D will prove to be an indispensable assistant for those who take a professional approach to 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 - from mobile phones to SMART TVs.

Program features:

  • Unity learning engine;
  • flexible multifunctional editor;
  • high compilation speed;
  • easy-to-learn interface;
  • compatible 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 for monetization volumes of up to $100 thousand annually.

In addition to the Free option, you can subscribe to two other extended versions:

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

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

The construction of all game actions is based on a fairly 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 add uniqueness to the product or use 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 manage yourself.

To work professionally with Unity 3D, you need some time to become familiar with the interface and capabilities of the application. To do this, you can find many videos on the Internet or attend specialized courses that are held in many large cities.

Please note that to work with 3D graphics you need to have modern computer with a hardware video card.

Pros:

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

Minuses:

  • To create a quality product, specific knowledge is required;
  • there is no possibility very much fine tuning 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 was also drawn with the tools of the hero of our review), but also to create gorgeous 3D presentations. It may take a little longer, but the wow effect for the audience is guaranteed.

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

Analogues:

  • Game Editor is a free application for creating games;
  • Construct 2 is a popular game constructor with a simple interface.
  • Construct 2 is a powerful program for creating 2D projects.

Unity is the engine on which most of the modern games on different platforms. Using the engine, it is possible to create games designed to run on computers (Windows, Linux, MacOS), mobile phones, tablet computers (Android, iOS) and even game consoles PlayStation, Xbox, Nintendo.

How to create games in Unity?

Unity is based on a component-oriented concept. In fact, any game consists of a mass of objects, diluted with additional components. For example, when creating a platformer, we create a GameObject, we additionally attach a graphical component to it, which is responsible for displaying the character, and a control component, which provides control of the character using a mouse, keyboard, joystick or touchscreen. The engine does not impose restrictions on the number of such modules. We can add as many components to GameObject as necessary. All work on the engine is based on the very creation of GameObjects and the application of suitable components to them.

Beginners may be misled by the apparent simplicity of the process, although this is not the case. To create a unique and popular game, you will have to write a lot of components from scratch. More precisely, in the Unity environment this is called a script. The native language for creating scripts is C#, but JavaScript and Boo (a trimmed version of Python) are also partially used. Creating your own components is not easy, one might even say it is a complex procedure directly related to classical programming. Without a sufficient level of knowledge in programming, you will have a hard time.

Supported Platforms

Many large projects prefer Unity due to the huge list of platforms compatible with the engine. The finished application can be launched on any computer operating system, popular mobile platforms and SmartTV. What can we say, even browser games and applications for specific platforms ( like Tizen OS) are primarily developed in Unity.

However, not everything is so smooth here. If necessary, you can write specific algorithms based on low-level code; for the same Android, you need to have a thorough knowledge of Java.

The same is true for iOS. Another one iOS feature, that it is possible to develop for it only from a computer or tablet from Apple. Without a Macbook or similar device, the release of the game will quickly stall and Unity has nothing to do with it, Apple itself imposes a similar restriction. The conclusion is simple: if you plan to develop iOS, you should select a suitable device for assembly in advance.

How and where to develop a game on the engine?

We can carry out the long process of game development both within Windows and Mac OS X. There are already versions of the editor for Linux, but we can’t count on their stable operation yet. A developer spends most of his time creating a game inside the Unity editor. We also have to spend a lot of time writing script code; we can create it either in standard MonoDevelop or in any third-party editor. Nowadays they actively use Visual Studio, as well as Sublime Text, but only with proper configuration.

Post Views: 19,374

We talked about how you can create your own game on Android using the Unreal Engine. In this article we will look at another equally popular game development engine - Unity.

Unity is a very famous engine among indie developers. Essentially, it is a cross-platform engine that allows you to develop 3D- And 2D-games. The feature that sets Unity apart from other engines is the low entry barrier for beginners, while there is a rich toolkit for professionals. Cross-platform allows you to develop applications for any platform, from desktop games to mobile ones.

It’s worth mentioning separately about the subscription system, since Unity is not a completely free product. There are several types of subscriptions:

  • Personal. Free version that contains all the main functions of the engine. It has the following limitation: annual income or the amount of funds raised should not exceed 100000$ .
  • Plus. Behind $35 per month various reports and analytics are provided, as well as the ability to change the splash screen, 20% -th discount on purchases in Asset Store and various minor benefits. It has the following limitation: income for the year or the amount of funds raised should not exceed 200000$ .
  • Pro. Behind $125 per month includes all the benefits of the version Plus and additionally professional service and premium support. No restrictions on turnover or volume of funds.
  • Separate versions for business (used by large companies).

Thus, for indie developers with small budgets, the version should be enough Personal or Plus, otherwise you will have to subscribe Pro. In this article we will use free version for the first launch.

Step 1: Install Unity

To begin installing Unity, you need to go to the Unity Store website, where you will be asked to select a subscription type. As mentioned above, let's choose Personal.

You will then be asked to accept the terms of use and download the installer. You can also check out system requirements to work with Unity.

After launching the installer, you will be asked to select which components you want to install. Since we need to create an application for Android, let's check the box Android Build Support. Also, if desired, instead of with Unity, you can install Visual Studio Community 2017 for programming on C#.

After this, all that remains is to select the installation path and start installing Unity.

Step 2: Register and configure Unity

Having completed the installation and launched Unity, we are asked to log in with our account.

Then you will again be asked to select a subscription, we will still choose Personal. In this case, you will need to confirm that the company's annual income is less than $100,000, or that Unity is used for training purposes.

At the end, you are asked to take a small survey in which you need to answer what you do and for what purpose you are installing Unity.

Step 3: Create a new project

Having configured Unity, we get to the project selection/creation screen. Here you need to click New to create your new project.

After that, in the window that appears, you are prompted to enter the name of the project and the directory where it will be located. Also don't forget to check the box 3D to use the editor in 3D mode.

When you're done, click Create project to create a project. After this, an editor window will open with a pre-generated scene.

Let’s not deal with the intricacies of programming for now and take a ready-made game as an example. This is why it exists here Asset Store, which contains a huge number of ready-made models, animations, sounds (and even games), both paid and free.

To open the Asset Store, you need to go to the menu Window choose Asset Store(key combination Ctrl-9).

The store window will open. Enter in the search bar " flappy bird style example game" and open a free example that we will use in our project.

Clicking Download and thus having downloaded it, you can then import it into your project. To do this, click Import, after which a warning will appear indicating that the project settings will be changed after import.

Once you agree to import, you will see a window where you need to choose which components to import. Select all and click Import.

Once the import is complete, you will see the new files in the Project Explorer. These are the game files. To open a scene in the editor, expand Flappy Bird Style - Scenes and double click on Main.

As a result, the game scene will appear in the 3D editor window.

You can check how the game works right in Unity by clicking the button Play above the editor window.

Step 4: Set up Android Tools

Note: if you use Android Studio, then you have already installed all the necessary components and therefore you can safely move on to the next step.

In order to build the resulting game on Android, you need to install the following tools:

  • Java Development Kit (JDK). You can download it from the Java website. By following the link, you will see at the very top Java Platform (JDK), click on Download next to the inscription, then select your operating system and start downloading. After that, simply follow the installer's instructions.
  • Android SDK. The most in a simple way To install the current version is to download Android Studio, with which this SDK comes. To do this, go to the Android Studio website and click Download Android Studio. The Android Studio installer installs the basic Android SDK components required for Android development.

Step 5. Preparing the project for launch

First, you need to change the development platform to Android. To do this, in Unity, open the File menu and select Build Settings.

In the window that appears, you need to select Android and then press Switch platform.

The platform switch informs us that we will be building an Android app. This means that when we build the application, Unity will create APK file. Switching platforms also forces Unity to import all project assets again. This won't take long on a small project, but keep in mind that on larger projects this operation can take a long time.

Now we need to specify the package name for the application.

Note: The package name is the application's unique identifier and is written in reverse DNS style in the format com.CompanyName.ProductName. Once your app is published on Google Play, the package name cannot be changed.

To do this, go to the menu Edit and choose Project Settings - Player.

A window will open on the right side of Unity with many different settings, such as application version, target and minimum SDK, icon selection, etc. Here we need in the block Other Settings find Identification and set the package name in the field Package Name. You can also change other settings if you wish.

Now all that remains is to specify the path to the Android SDK and JDK. To do this, go to the menu and select Edit - Preferences.

In the window that appears, you need to go to External Tools and in the fields SDK And JDK indicate the appropriate paths, and then close the window.

Step 6. Build and run the application

It's time to build your first Unity application. To do this, select from the menu File - Build Settings. A window will open in which you will need to add the scene that needs to be assembled. Since we already have this scene open in the editor, just click Add Open Scenes to add it to the build, after adding it you will see it in the list of scenes.

All you have to do is click Build, after which Unity will begin building the application. Before doing this, you may be asked to select a folder where the collected application files will be saved, as well as a name for the APK file.

Note: on this moment, if you have the alpha version installed in the Android SDK Build-Tools(version 28.0.0-rc1), Gradle will throw an error when building. To fix this, simply remove this version from the Android SDK.

As a result, the assembled APK file will appear in the folder you specified, ready for installation on an emulator or on a real device.

Let's see what's inside the assembled APK. To do this we will use the utility APK Analyzer, which is included with Android Studio,

The uncompressed APK file size is 21.1 MB, in a compressed 20.9 MB. As you can see from the graph, most of the volume is occupied by third-party libraries added by Unity. Then in assets All resources that are used in the assembled scene are located. File classes.dex contains total 89 classes and 479 methods.

Moreover, if you look at AndroidManifest.xml, the application consists of one activity.

Conclusion

That's all. In this article, we learned how to install and configure Unity, and also built our first application on Android.

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

Do you play computer games? If yes, then, for sure, in the process of passing the next blockbuster game, you sometimes had thoughts like: “But here, I would have done it wrong!” Do you want to experience the role of 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 using the so-called “hardcore” method. That is, for full development it was necessary 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 very valued (and still are)...

Today, the threshold for entry into 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” developers, 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 the virtual stage and configure all their parameters. That is, the programmer’s task is only to write the game logic correctly!

However, for the convenience of work you have to pay for a slight increase in the size of the project (sometimes even several times!) in comparison with its analogue, written in the old “hardcore” way. This is precisely why some developers don’t like engines or try to write their own, which use only the components they need...

But you and I are far from being true programmers :) Therefore, let’s start creating 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 a ready-made game for any device;
  • relative ease of engine control;
  • good functionality expandability by connecting plugins;
  • relatively small size of the final game assembly (compared to other engines).

The main trump card of Unity3D, naturally, is its versatility and multi-platform. You can port the finished game (possibly with minor modifications) to either a PC (Windows, Linux or MacOS), or to Android, or to PlayStation or XBox! To do this, we only need to download the engine itself, which, by the way, “weighs” more than a gigabyte and the necessary SDKs (if we plan to develop for mobile platforms or consoles). If you want to make a game for Windows, then you don’t need to download anything additional, 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 ease of working with it.

When everything is downloaded, you can unpack the Android SDK to any folder 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 the installation. After installation, the engine will start and first we will 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 screenshot above), we will be asked to specify the folder for saving the project (its name will coincide with the name of the project), import some standard sets of functions (we don’t 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

Once the project is created, 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 as you wish. I have it configured like this (from left to right and top to bottom):

  1. Hierarchy window - displays the hierarchical position of active and inactive objects in the scene. By default, the only object immediately in the list is the Camera (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 an object selected in the hierarchy or on the stage and allows you to edit, supplement or delete them.
  4. Game window - displays game world, which is visible through the camera and allows you to select the size of the game's virtual test window in pixels. Also, it allows you to activate maximizing the game window to 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: loaded images, sounds, models, etc. Also, using 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 you requested (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 run 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 musical instrument: Indian folk drums called "tabla", so to get started, let's 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 "Folder" in 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” whatever 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 stored in it (sorted into subfolders). Plugins, as the name suggests, stores all additional third-party feature sets (so-called “assets”), of which there are quite a few on the Asset Store - a store of extensions for Unity3D.

Importing files and creating game objects

Before creating a new one game project It is advisable 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 by simply dragging them into the desired folder. Let's start with the pictures...

After the images appear in our Images folder, they should be configured a little:

The fact is that by default, Unity3D compresses all images added to the project with loss of quality. If we don’t need such a loss (especially important 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 width of the image (default - 1024 pixels). After all the changes, you must 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 the case by selecting the 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, therefore, we need to adjust the size of this view by dragging the frame directly on the scene or 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 configure the rest of the pictures. When adding, we see that some of them are too large for our game. You can reduce them either physically in a graphic editor, or using 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 it by half). It is also advisable, in order to avoid overlaps, to assign all game objects (except the background) a non-zero order of layers (Order in Layer):

The last step in preparing game objects from pictures will be to “hang” colliders on them. In Unity3D, colliders are used as interaction detectors between objects. That is, in essence, 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 in the Inspector window click the "Add Component" button. In the list of components that appears, we look for Physics 2D (regular 3D physics will not work in our mode) and there, of all the options, “Circle Collider 2D” suits us best. We choose him. A green outline will appear around our object, which displays the boundaries of the collider. All that remains is to check the “Is Trigger” box so that our collider only registers clicks and no longer interacts with the surrounding game space:

We repeat similar steps for all remaining objects. Only our background will differ from other objects. For it, we will use Box Collider 2D and set Position Z greater than zero to push the collider and the background itself into the background (we will need this a little 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 customize them a little too:

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

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 from the “Audio” section to it. When the component is added, select the corresponding “Audio Clip” button and uncheck the “Play On Awake” checkbox, which is active by default:

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

First script

Before we start analyzing our first script, it’s probably worth saying a few words about the scripting system itself in Unity 3D.

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 it is easier to learn scripting in Unity using JavaScript as an example. However, this language is not as convenient as the others, and in the future you will most likely have to relearn it. 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 provides hints for quick input standard methods, classes and functions, as well as a syntax checking system. However, the downside for me was the bulkiness and high resource consumption. Fortunately, in Unity settings You can install anything as a text editor, so I installed the lightweight and functional Notepad++ for myself (almost all examples will be shown in it).

And one last thing. Naturally, without reference materials you won’t get far in mastering all the intricacies of the engine, 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 still sometimes unstable);
  • http://docs.unity3d.com/ru/current/ScriptReference/index.html - official manual guide to scripting in English;
  • http://unity3d.ru/distribution/index.php - Russian-language developer forum for Unity 3D;
  • 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 - official reference book on C# from Microsoft in Russian.

Well, in order not to delay for a long time, I suggest creating the first script right away. If there are a lot of scripts, 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 call our new script, for example, Sounds and open it with a double click. By removing the standard Update and Start methods, and then specifying the necessary ones, we get the following type of script:

If you have not reconfigured the editor, then our script will open in MonoDevelop. Let's 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 engine itself, and “using System.Collections” is a library containing a number of built-in classes for running the script under different systems).
  2. Declaration of class and variables. In C# there is no concept of a script 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 practically the same thing :) The main thing to remember is that the class name must match the name that we gave to the script. The peculiarity of variables in C# is that they must be typed (except for temporary ones, which are declared in the script itself). In practice, this means that the access level (private or public) and type (int, float, bool or, as in our script, AudioClip) must be specified for the variable. In this case, you can give any name to the variable. Or you can immediately give it a value attribute.
  3. A set of methods and functions. A method in C# is called 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 not difficult 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 must make them 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 “void OnMouseDown()” method. Previously, it was only responsible for processing a mouse click, but in new versions it is also interpreted as a touch on the touch screen. In it we write the conditions by which we check the names of the pressed colliders and, if we detect the pressing of one of them, we output the corresponding sound (we use the standard function audio.PlayOneShot();).

When writing code, carefully make sure that all opening and closing parentheses are present, 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 methods and functions in names capital letters. They are also often the cause of errors. And, of course, follow all the signs (dots, colons and parentheses), in short, the syntax of the language. It will be difficult at first, but over time you will start writing from scratch without mistakes!

When the script is ready, select it and assign a different sound to each variable in the Inspector window. Now all we have to do is apply our script to the objects on the stage. The easiest way to do this is, again, 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 to which we dragged it. Accordingly, we drag the script onto all objects that should sound in the game and we can try to launch it. When you click on our game buttons, the specified sound will now finally sound!

Introduction to GUI

In principle, the Game is already functioning for us, but it is somehow too “bald”. Something is missing from it... And, at least, the inscription with the name that is in front of us! In other words, you need to implement some clear 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) is fully present. The main thing is to learn how to use it! Let's look at how you can make a simple heading using the GUI in Unity.

To do this, let's create a new script called Interface and change it as follows:

Let's take a closer look at the script in the screenshot. Here we write only one public variable of a new type, GUIStyle. This type allows you to visually change the design of the elements to which this style is assigned. Styles are useful when you have many interface elements of the same type (for example, buttons), but they must have different appearances.

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

GUI scripts can work from any game object, but usually they are advised to be “hung” on the camera, which is what we will do by dragging the script onto the Main Camera object. Now, if you select it in the Hierarchy window, then in the Inspector window we can see the public variable of our style, expanding which 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 a button you need to specify three of its options (Normal - normal view, Hover - when hovered and Active - when clicked), set indents and customize the font. By default, the only one available in Unity 3D The font is Arial, but you can manually load any other font into the project and apply it in the "Font" field, setting all the associated parameters.

What is interesting and at the same time not entirely convenient is that GUI elements are not displayed on the stage until we launch 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, as a last example, I suggest creating a help window, which normal developers usually provide for 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 attach a collider to 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 the styles that 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 need to immediately create it in the “Project” window from the context menu: “Create” - “GUI Skin”.

Our second variable is logical (or in other words Boolean). It can only have two values: true or 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 text describing our game.

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

But let's get back to the rest of the code. The already familiar “void OnMouseDown()” method here will serve as a switch for the “isVisible” variable using a simple condition. However, after the condition there is one more 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 parentheses). 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 is a “+” sign between all the data.

Further along 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 is usually used to display various text or graphic data.

Notice how we set the positioning for the box. Here, all values ​​are indicated not directly, but using mathematical expressions, which, in fact, is an analogue of “rubber layout” in web development. The problem is that if you specify the exact sizes of GUI elements at different screen resolutions, they will not adapt and can be either too small or, conversely, large. In the next version of the engine, the developers promise to make the GUI adaptive, but for now they have to be perverted :(

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

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

Now everything works, but it’s not always convenient to click the help button to hide the description back. To disappear any notifications, it is more common to poke at any free space than to aim at the buttons. And this is where it comes in handy for us: we made the “isVisible” variable static, as well as the collider attached to the background image...

Let's return to our very first script ("Sounds"), which tracked button presses to play sounds. In it (more precisely, inside the "void OnMouseDown()" method), we only need to write one line:

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

With this line we set a condition: if the name of the clicked collider does not equal the name of the help button, then the “isVisible” variable in the “Help” script will be equal to “false”. You just need to make sure that the "isVisible" variable has the "static" prefix, otherwise we'll get an error.

Now, when we launch, we will see that our help window closes when we click not only on the button in the upper right corner, but also when we touch any free part of the screen. The only thing that can be improved is to make the window hide even when you click on it... This will be your “homework” ;) I will only say that the GUI box will need to be replaced with a similarly designed button, again, with settings skin and writing a function that changes the "isVisible" variable. That's it, I'll 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 to do 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 the game for PC, then you do not 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 up the “Preferences” item and in the window that opens, go to the “External Tools” tab. Here we look for the line “Android SDK Location” and in it indicate the path to the unpacked archive with the SDK (see screenshot below). By the way, here you can change the default active MonoDevelop text editor 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 assembly. If there is only one scene (as in our project), then all you need to do is 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 adjust their desired order by dragging and dropping:

The next step is to select the build platform (we are planning the game for Android, which means we select it) and click the “Player Settings” button at the bottom. The Inspector window will open a number of settings, some of which are required 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 list of settings.

At the bottom, in the "Other Settings" section, there are two required parameters: "Bundle Identifier" and "Bundle Version". The default version is set to 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 build settings at your discretion or not change them at all. The main thing is that now the compilation can 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 review lesson on creating simple applications for Android. So that you can repeat everything we talked about, at the end of the article I will give a link to an archive in which all the game resources will be stored in the form of a separate folder (if you want to do everything from scratch) and in the form of 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 Click 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.

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

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

P.S. Permission is granted 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.

Development mobile applications is one of the most lucrative occupations in the computer industry. Creating a game on Android costs several hundred or thousand dollars, and the profit can reach a million dollars. In this regard, many people are interested in developing applications for their phones. In this article you will learn about how to create a game on Android from scratch using a computer, which engine and designer is better to choose.

None successful game is not complete without beautiful graphics, so creating a 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 elaboration. 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

The gameplay and the main capabilities of each character are described here. Also here is a description of the features game items– weapons, first aid kits, armor and others. Essentially, functional specifications are the rules by which gameplay occurs. 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 cause damage, how much health a hit will take, and what characteristics will increase when using various equipment. Also contained here 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 do not have experience in creating applications on Android, before creating your own, download from the Play Market and analyze popular games and transfer the best solutions to your project.

Game engine

The basis of any game is the engine. This software, allowing 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 make the process of writing programs easier, third-party developers create their own game engines specifically for Android applications.

Each offers different features: some are designed for 3D, others for 2D, and can support multiplatform. 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?

The designer is a program that combines a game engine and an integrated development environment. The designer 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 beginning mobile application creator, choosing a designer is one of the most crucial moments, because the fate of the future application will depend on its capabilities.

The designer allows you to create games of various genres for Windows, Android and iOS. Offers big choice ready-made locations, objects, characters and sound designs, so creating your 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 a game on Android is not an easy task, but it is very profitable. If you decide to develop a game and make money from it, first work out the idea. Next, write a “design document” and decide on game engine who can maximize its potential. After this, you can proceed directly to creating the application in the designer.

Video

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



Solitaire Solitaire