How to make a game in Unity: it will be shown by the example of a simple mobile 3D maze game.
To demonstrate, I'm going to develop a game in which the player will move around the map by tilting a mobile device, in the image of a ball, to find a blue square. This is a great first project in Unity for beginners, which will teach some basic concepts.
First you need to create a project. To do this, you need to go to Unity Hub and create a 3D project.
Building a maze.

Now we are going to arrange a few items in our scene. First, we are going to add the earth, which in Unity language is called a 3D-plane.
To add this to the scene, go to:

GameObject > 3D Object > Plane
This will result in a flat square appearing in your Scene. "Scene” is actually another word for a level in Unity, although it can also refer to things like menus. The scene window allows you to view and manage individual elements that are in your game world.
Next we will add some cubes. Insert the first one by going to:

GameObject > 3D Object > Cube
This will allow you to insert a cube, which by default will be displayed right in the center of the plane. To move elements, you can select them in the scene and then select the arrow icon in the upper left corner. This will allow you to drag the element along all three axes.

For our purposes, the cube can be left where it stands. Now it is necessary to make several more such cubes. To do this, select the first one and press Ctrl + C. Now press Ctrl+V to paste and the new cube will appear right on top of the old one. Another cube will appear in the hierarchy on the left. The hierarchy is essentially a list of everything that is in your scene, which makes it very easy to find individual elements and manipulate them.

Drag the selected cube away from the first cube so that it is right next to it without a gap. To do this exactly, you need to hold down the Ctrl button while dragging. This causes objects to move to a predefined unit of measurement, which you can control in the settings.
Our goal is to create a maze, so drag a few of them to make something similar to a maze. The character will start in the upper left corner.

If it needs to be done at a fixed angle, hold down the Alt key and then drag it with the mouse to change the viewing angle. You can also use the mouse wheel to zoom in and out.
Creating a game character.
Now you have a level, but in order to know how to make a game in Unity, you also need to create characters that can be controlled. For the sake of simplicity, I go with a small ball that can be rolled around the maze.
To create this ball, just place the sphere in the scene once you have added the boxes.














However, this time we want to give the figure physics. To do this, you just need to select it in the hierarchy or in the scene view, and then view the "inspector” that is displayed on the right. This window displays the properties of any selected element and you can edit them exactly. It also allows you to add "components” to game objects, which means you can change their behavior.
Click "Add Component” and then:
Physics > RigidBody.







RigidBody is a script that, in fact, provides ready-made physics for application to any object. Now our ball will fall on the stage, ready to move! This is the real strength of using a game engine like Unity 3D: it provides built-in features that would otherwise require months of programming.
I have reduced my default sphere size to 0.5 by editing the scale on all three axes in the transformation (also found in inspector).

Fixing the camera.
To play this game, we want to look at the action from the top down. To do this, we need to change the angle of the camera and its viewing angle. So select a camera in the Hierarchy and you will see a small window appear in your scene showing a preview of what it sees.
This also opens up some details in the "Inspector" on the right, where it says “Rotation”, we will change the X axis to "90".
Now move the camera up and away from the scene until you see the entire map.

But we still need a way to control our game. To do this, we will need to write a script.

Create a new folder in your resources and name it "Script". Now right click anywhere here and select:
Create > C# Script
Name your new script "TiltControl".












Once this is created, double-click on it to open the default editor (IDE). This will usually be Visual Studio.
Now just delete everything that is there at the moment and replace it with:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TiltControl : MonoBehaviour
{

public Rigidbody rb;

// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}

// Update is called once per frame
void Update()
{

}

void FixedUpdate()
{
Vector3 movement = new Vector3(Input.acceleration.x, 0.0F, Input.acceleration.z);
rb.velocity = movement * 5;
}
}

Here we call the solid body component that we added earlier, and then add the velocity along three axes based on the accelerometer in the phone. In other words, the player will now be able to move the ball by tilting the phone.
Now go back to Unity, select the sphere and drag your TiltControl script to the inspector at the bottom where it says "Add Component". Now this means that the code in your script will affect the game object to which you have attached it.

Before we test the game, you should also check the box labeled "Freeze Position Y" under the restrictions. This is important because it will prevent our ball from jumping out of the maze if it moves too fast!

Creating an Android game in Unity.

To do this, select File > Build Settings. Now select Android from the list of platforms, then select "Switch Platform".
To do this, you will need the Android SDK and Java JDK to be already installed and located on your computer. You can ask Unity to do this for you at runtime, otherwise you will need to download them separately and then find the necessary files. This can also be achieved using Unity Hub.

You should also click the button labeled "Add Open Scenes”, which will add the level you created to the assembly.
Finally, click "Player Settings” and then scroll down to the place where Default Orientation is specified. You want to set this value to the “Landscape Right" position, which will prevent the screen from rotating while your players are having fun!
To create and test the app, you only need to click "Build and Run" while your smartphone is connected. Make sure you have enabled USB debugging in the Developer Options menu.
If everything goes according to plan, you will see the game appear on your device's screen a few minutes after the build.

Victory.
But it's not a real game until you can win. To add winning conditions, you need to turn one of our blocks into a goal.
Drag a simple PNG format in the form of a blue square into the project window (you can create a new folder called "Color” or something like that if you want). Select one of the squares in your game and then drag that color onto it.
Now we need to create another new script, which I call "WinBlock". This one looks like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WinBlock : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}

void OnCollisionEnter(Collision collision)
{
Application.Quit();
}

}

What he's doing is checking to see if anything bumps into him. All of these cubes have "Colliders" by default, which are boundaries that allow the Rigidbody body to know where obstacles start and end. This is another common feature of video game engines that saves developers a lot of time.
So when something new touches that boundary, the game ends. Given that the only thing that can move is our little ball, we can safely assume that it will be the culprit.
You will need to do a lot more to make this game fun, not to mention that it can be sold. You need to add textures, music, graphics, and refine the gameplay. If we were assembling this into a larger project, we would also need to rethink how we arranged the elements in the scene.
Nevertheless, as a starting point, I think you will agree that what we have managed to achieve in a very short time is impressive. And along the way, we have learned a few basic lessons.
Adding music and volume settings.
© Alexander Vinogradov's course project
VS-1 Group
Rybinsk Aviation College
Social network
This site was made on Tilda — a website builder that helps to create a website without any code
Create a website