0% found this document useful (0 votes)
2K views

Unity 3D Game Development, For Beginners

This document provides an overview and summary of a professional game development guide for Unity. It is aimed at game developers, programmers, and freelance developers who want to learn game development using Unity and earn money by publishing games. The guide contains 100 pages divided into theory and practical implementation sections. It teaches the basics of Unity and provides step-by-step instructions to build a sample Word Cross game, including how to publish and monetize it. Following the guide will help readers master Unity game development and learn how to earn through game monetization. The sample project begins by setting up a new scene and adding basic 3D objects like a cube and floor plane to experiment with the transform component and scene editing tools in Unity.

Uploaded by

K Bhanuvardan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Unity 3D Game Development, For Beginners

This document provides an overview and summary of a professional game development guide for Unity. It is aimed at game developers, programmers, and freelance developers who want to learn game development using Unity and earn money by publishing games. The guide contains 100 pages divided into theory and practical implementation sections. It teaches the basics of Unity and provides step-by-step instructions to build a sample Word Cross game, including how to publish and monetize it. Following the guide will help readers master Unity game development and learn how to earn through game monetization. The sample project begins by setting up a new scene and adding basic 3D objects like a cube and floor plane to experiment with the transform component and scene editing tools in Unity.

Uploaded by

K Bhanuvardan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

This Professional's Game

Development Guide (Theory +


Practical Unity Game Source
Code) is perfect for…
✅ 🕹
Game Developers (Jr to Sr) - Beginners in Unity Game development who
are struggling to find a practical guide with perfect commercial source code to
understand the depth of gaming development to intermediate and senior developers
who are enthusiastic about learning continuously from looking into other developer's
way of writing code.

✅ Programmers - This guide will be perfect for mastering game development


quickly by the following theory and implementing step-by-step practical premium
source codes. This is for you if you want to switch to game development or anyone
enthusiastic to explore by learning and earning continuously in various languages.

✅ Freelance Low-Code Developers: 🚀 - Anyone who quickly wants to develop


unity gaming applications and publish games in the mobile app stores by the
following theory and implementing step-by-step practical premium source codes that
are provided as an extension of this guide.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 1
✅ Everyone 🤑 - who is interested in making games with Unity to learn and adapt
quickly to unity gaming development with not just theory steps but also with the
practical free premium game source code and guide included in this book.

What you will find inside? 🧾🎁


The comprehensive e-book is divided into simple and easy steps, counting 100
pages. starting parts are theory-based, explaining the best methods of Unity gaming
practices, and the balance part is a step-by-step guidance implementation focused,
going over the free premium unity game source code Word Cross game
Installation 🕹 and how to earn 🤑
by publishing in any apps store like google
play, app store and many others.

⭐ Part 1:
Learn the Basics of the Unity Editor, scenes, game objects and components
Working with object transforms both from the Inspector and scripts Basic UI
modifications and importing fonts, required assets of your choice.

⭐ Part 2:
Building your premium unity game source code Word Cross game Installation

Publish and monetize your game by integrating to 10 Ad Networks.

What you'll achieve by following it?


The "Learn & Earn by game development" e-Book will help you:
📖
💎 Master the smart way of unity gaming development
with over hundreds of pages available out there but this helps you to acquired full of
pure unity gaming development knowledge from end to end and fully explained
framework you can follow from A to Z, you’ll learn the exact process how the gaming
development is managed.

💎 Learn and Earn by unity game development


The goal is learning is much more motivated by knowing and exploring real-world
applications and monetizing them. This book is not just to make go through the
variety of concepts infused to your head but If you're interested in learning game

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 2
development and want to earn some money while doing it, Unity is a great platform
to use. With Unity, you can create games for various platforms, including PC, mobile,
and With consoles.

Part 1:

Scene basics
Start by opening Unity. Click New, enter a name for the project (“Zenva 3D
Platformer”), make sure 3D is selected, then click on Create project.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 3
This will bring us to an empty Unity scene. I will now describe some of the main
panels and elements present in the Unity Editor. If you are already familiar with the
basics you can skip straight to the next section.

What is a scene? The word “scene” comes from the Greek skene, and was used
back in ancient world for the area in the theater that faces the public, where all
the action takes place. In Unity the definition is not too distant: a scene in your
game is an object that contains all game objects such as players, enemies,
cameras, lights, etc. Every game object within a scene has a position which is
described in coordinates X, Y and Z.

The following image shows the main elements we find in the Unity Editor:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 4
Project Window: this area shows the files and folders of our project. The only
folder we’ll see in our new scene is the Assets folder, which is created
automatically and it’s where we’ll place all the game assets (3D models, scripts,
audio files, images, etc).

Hierarchy Window: shows all the game objects that are present in our scene.
By default, Unity creates a camera and a directional light.

Scene View: shows the 3D view of your game scene. All the objects that you
create in the Hierarchy Window will appear here in their corresponding X, Y, Z
positions, and by using different “gizmos” or tools you can move, rotate and
scale these objects around.

Game View: this view shows what the game actually looks like. In this case, it
shows whatever the camera (which was created by default) is looking at.

Inspector: whenever you select a game object, the Inspector will show different
options and properties that are available for that game object.

Toolbar: this area contains different tools we can use to modify our game
objects, move around the scene, and modify how the Editor works.

When creating a new scene the first thing you’ll want to do is to


save it. Let’s go to File – Save Scene and give it a name
(“Game“).

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 5
As a Unity project grows, it becomes paramount to keep your
files organized. In the Project Window, right click in Assets and
create a new folder called Scenes. Drag our newly created
Game scene in there.

Transform Component
All game objects in a scene have a Component named
Transform. What is a component? Think of components as
reusable “Lego pieces” that can be used in different objects. A
component provides a game object with certain behaviors and
properties.
As we mentioned before, all game objects in a scene have a
position described in coordinates X,Y,Z. That in Unity is called
the Transform component. This is the only component that is
present in all game objects. There can’t be a game object without
a Transform component!

On the Hierarchy Window, click on both the default camera and


directional light, and observe how the Transform component

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 6
appears in the Inspector, indicating the position of the object,
plus values for rotation and scale.

Lets create a Cube to experiment with transforms. In the Hierarchy Window, right
click and select 3D Object – Cube.

Click on the cube and change the position values in it’s Transform component to
see how it’s position in the scene changes as well. Experiment changing the
scale and rotation as well.

A scale of 1 means no change in size. If you set it to 2, it will twice the size in that
axis. If you want it halved, set the scale to 0.5.

Notice that Unity uses what’s called a left-handed coordinate system:

Rotation values are entered in degrees. If you enter, for instance 45 in X, that means
that the game object will rotate 45° around the X axis. To determine to which side it
will rotate, use the left-hand rule as shown in the image below. If the rotation value is
negative, use your right hand.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 7
Besides changing the Transform properties of a game object from the Inspector,
you can do so by using the Toolbar buttons and the “gizmos” in the Scene View:

Unity units

You may wonder, what’s the unit of measure in a Unity game? if we move an
object from X = 1 to X = 2, how much would that represent in the real world?
Unity uses Unity units. By convention (and this even includes some official Unity
tutorials), 1 Unity unit is 1 meter.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 8
The Floor
Let’s go ahead and create the floor of the game. For that, we will use a plane. Right
click on your scene in the Hierarchy Window and select 3D Object – Plane. This will
bring up a plane into our scene. From the Hierarchy Window, we can rename this
object by right clicking – Rename, by selecting it and pressing F2, or by single-
clicking on it after we’ve selected it. Call it “Floor”.

We will now create a new material so that it can look green. Un Unity, a material is
an asset that controls the visual appearance of a game object. We can easily create
materials from the Project Window and assign them to objects in our scene.

Create a new folder inside of Assets called Materials. Inside of this new folder,
right click and select Create – Material. This will create a new material file.
Rename it to “Grass”. If you click on this file, the Inspector will show the
properties of the newly created material. Click on the color white in Albedo and
pick a color for the grass in the game:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 9
Now drag the material file to the floor in the Scene View. The plane will look
green, and if you click on it, you’ll see the material in the Mesh Renderer
component in the Inspector.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 10
Lastly, since the floor won’t be moving around in the game, check the Static
checkbox located on the top-right of the Inspector.

By making a game object static, we are informing Unity that this object won’t be
moving in our game. This allows Unity to perform behind the scenes optimizations
when running the game.

Adding more game elements


Let’s add the remaining elements of our game. Start by creating the new materials.
Pick whichever color you want for each one:

Platform

Coin

Enemy

Goal

Player

This is what mine look like:

What we’ll do next is add all the remaining elements to create our level, so that we
can get a clear idea of what it will look like. We haven’t implemented our player, the
behavior of the enemies or coins yet. Moreover, we haven’t written a single line of
code. However, it’s good practice to design a game as early as possible.
Moving around blocks in Unity like we’ll do now is very easy and anyone can do
it. This process can give you a very clear idea of what your game will look like,

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 11
and allow you to save time further down the road, and to show other people what
the game will look like. This process is called prototyping.
Let’s thus begin this process by adding some cubes to be used as platforms. Use
the position gizmos or the Inspector to position them in different places. Set their
scale in Y to a smaller value to make them thinner, and scale them up in X and Y
so make them wider. Make sure to drag the Platform material we created to give
them the color you want.
Since platforms won’t be moving make sure to set them as “static” (unless you
want to create moving platforms of course!).

As we create more platforms, the Hierarchy Window can start to


get crowded of elements. Game objects in Unity can be children
of other objects. This means that their position is relative
to that of the parent. In this case, grouping all the platforms
inside of a single parent object can help us keep this window
more clear – we won’t be moving this parent object.
In the Hierarchy Window right click and select Create Empty.
Rename this new object to “Platforms”. Drag and drop all the
platforms you created into this object. Notice that even though
Platforms is empty (it doesn’t render anything on the screen), it
still has a Transform component. As we said before, this
component is always present in Unity game objects.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 12
For the coins we’ll start by creating a cylinder in the Hierarchy
Window (3D Object – Cylinder). Shrink it (this means, scale it
down) on Y so that it looks more like a coin. Also, scale it down
on X and Z to make it smaller (I’ve never seen a coin with a 1-
meter diameter!). Lastly, rotate it 90 degrees in X or Z.

Rename the cylinder to “Coin”. Drag the Coin material into your
coin and you’ll have your coin ready! Once we get into scripting,
coins will have a C# script associated to them which will
determine how they behave. Since we’ll have many coins, having
to re-create them each time is not the best approach. Imagine we
want to change how all coins behave at once? We need to create
what’s called a prefab.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 13
Unity prefabs are templates of game objects that can be reused
(even used in different projects), and that allow us to generate
many game objects that share properties and behaviors.
Changes made to a prefab are reflected in all of it’s instances.
Create a new folder in Assets called Prefabs to keep our code
organized. To create a prefab, simply drag and drop the coin you
created (from the Hierarchy Window) into this new folder in the
Project Window.

Now that we have our prefab ready, you could safely delete the coin from the
Hierarchy Window, but you don’t really have to. To create more instances of our
prefab, simply drag and drop the coin Prefab into the Scene View. Do it many times
(you can also do it once and duplicate the object with Control + D).
If you select any of these instance you’ll see a Prefab area in the Inspector. If you
click on Select in there, see how the Coin prefab is selected. If you make
changes to this particular instance (for example, change the scale, rotation or
material) and press Apply, the changes made will be applied to the prefab itself,
changing thus all other instances!

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 14
Place coins across your level. This will help you get familiar with moving around
the scene, duplicating or copying and pasting objects, and using the position
gizmo. When you are done we’ll finish off with the design of our level. Make sure
to group all the coins in an empty object, just like we did with the platforms
before.

We’ll now follow a similar process for the player, enemies and the
level goal. For the player and enemies do the following:

Create a cube

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 15
Scale it to 0.6 in all axes

Assign the corresponding material

Drag to the Prefabs folder

Drag the newly created prefab on to the Scene View to create an instance (for
the enemy, create more than one, and group them in an empty object)

We can, of course, change of all this later, so don’t much in too much thought or try
to be perfectionist at this stage.
For the goal, the only difference is that instead of a cube, we’ll use a sphere (3D
Object – Sphere). The process described about is the same.

This is what my level looks like:

Pro tip: when moving a game object with the position gizmo, if you keep the Control
key pressed (CMD in Mac) the object will move in fixed increments (which you can
change in Edit – Snap Settings). If you grab the object from it’s center, and press
both Control and Shift, the

object will snap to the surface of any near object. This is useful to place the
player on the ground with precision. Read the documentation under “Snapping”
for more details.

Coin rotation script

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 16
Coins will always be rotating around the Y axis. This is really a cosmetic aspect of
the game. As you might have guessed, I like to create a rough version of the full
game before diving into this kinds of details (which I tend to leave for the very end).
However, I think coin rotation can give us a very simple example to cover the basics
of Unity scripting, so this will be our first approach to scripting, in preparation for the
more complex implementation of the player controller.

Unity scripts are a necessary part of any game. Scripts can be written in C#,
UnityScript (aka “JavaScript for Unity”) and a language called Boo. C# is the
most popular option these days, so that’s the only language we’ll be using.
Let’s begin by creating a new folder inside of Assets called Scripts. In this new
folder, right click and select Create – C# Script, name it CoinController. Voilá! You
have created your first Unity script.
Double click on this new file and Visual Studio will open. The default contents are
as follows:

What we have here is:

A new class has been created for us. This class is called , and inherits

from another class called . Think of a class as a blueprint (“a


recipe to make a cupcake”) that can be used to create objects

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 17
with certain characteristics and behaviors (“an actual cupcake”).
Objects created from a class are called instances of that class.

Our new class has two methods: and . In Unity, there are some reserved method
names used in classes that inherit from . We’ll now

explain what these two methods do. You can find the full list of
methods here.

is called on the first frame of the game.

is called on every frame, multiple times per second!

On the other hand, we do want to rotate it slightly on each frame.


One way to do that is access the transform of the coin, which as

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 18
we’ve seen contains it’s position, scaling and rotation values.
We’ll start by defining a rotation speed, as a public variable, and
give it a default value (more on this later).

A public variable is a property of the class that can be modified


from outside the class. As we’ll see shortly, by assigning this
property as public we’ll be able to modify it directly from the Unity
Editor.

Basic physics stats that speed is equal to distance divided by


time. This means, distance is equal to speed times time. We’ll
use that formula to determine how much the coin needs to rotate
on each frame:

The rotation needs to be about the vertical axis (Y). We can


access the object’s transform and make it rotate as shown below:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 19
allows us to rotate the transform. For the full documentation see here.

gives us the vertical axis. An alternative would be to create a new object like so:

The last parameter needs to be specified in this case, and it means that the
rotation needs to be to the “up” direction in the world, not relative to the object.
Remember how we created our coins: we inserted a cylinder, reduced it in size
then rotated it so that it would look like a coin. If you don’t specify this parameter,
the rotation will be applied on local coordinates, in which the Y axis is tilted.

Last but not least, we need to attach this script to our coin
prefab. So far, Unity has no way of knowing that this script is to
be used on coins!
Select your coin prefab (from the Prefabs folder). In the Inspector
click on Add Component, select Scripts – Coin Controller. This
action will attach the script to all the coins you have created.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 20
Notice how we can also change the rotation speed from here –
all public properties show in the Inspector and can be edited
directly from the Unity Editor. This is quite useful in case you are
working with people who don’t do coding but need to make
changes to the game.

See it in action! Press the “play” icon on the Toolbar and see how
the coins rotate in either the
Scene View or the Game View.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 21
Where did the “100” for rotation speed come from? The
answer is: from trial and error. When making games you’ll quite
often need to set arbitrary values such as speeds, jumping
distances, etc. What I usually do is throw in a number and adjust
until it looks/feels good.

Player movement
In this section we’ll implement player movement using the arrow
keys. Let’s first place the camera in a position where the whole
level can be seen easily. See below where I’ve placed mine (you
can copy the values in Transform if you want). Feel free to
manually adjust it.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 22
Our player will be subject to physics laws: gravity, momentum, etc. For that, Unity
provides a component named Rigid Body, which we need to assign to our Player
prefab. In the Inspector click Add Component, select Physics – Rigidbody.

Create a new script in the Scripts folder and call it PlayerController. We’ll start by
adding some public properties for the walking and jumping speed of our player.
Attach the script to the Player prefab as described in the previous section.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 23
We’ll begin our implementation of basic cursor keys movement by reading user input
from the

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 24
input axes

vertical axis

If you are curious, you can see the axes available if you go to the menu Edit –
Project Settings – Input. We’ll be using Horizontal and Vertical.

Projects

(left) to 1 (right). shows values from -1 (down) to 1 (up). The value of 0 is shown
when no key is pressed.

Each time the input is read, we’ll move a certain distance which can be
calculated as speed * time. (remember: speed = distance / time, which means
distance = speed * time).

We’ll create a vector that points out where we are moving, based on our current
position:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 25
Now, how do we actually move our player? We need to access the player’s rigid
body in order to do that (yes, we could just move the transform like we did with
the coins, but in this case we want to have an accurate physics simulation with
velocity, gravity, etc, so we need to use the rigid body instead).

the start of our script, for which we can use the method), so that we can then
access it for movement, jumping, and whatever else we need.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 26
You can now move around! But as you crash against an enemy or a platform
you’ll notice that the player rotates after the collision:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 27
Our player is represented by a rigid body which simulates real physics. If you put a
dice on a surface and hit it on a side, it will of course rotate! What we need to do is
disable our player from rotating, which can be easily done from the Inspector. Find
the Rigid Body component of the player prefab, under Constraints go and check
Freeze Rotation for all axes.

Player jumping
We can now move our player around the game with the arrow keys, and it’s time to
give it the ability to jump. Implementing proper jumping logic will take some thought,
but we’ll go step by step covering all that it entails.

Unity comes with an Input Axis called “Jump”, which activates with the spacebar
by default. Go to Edit – Project Settings – Input to double check it’s there on your
end.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 28
When should the player be allowed to jump? Should it be allowed to jump while
it’s already in the air? You start to realize that there are some rules around when
the player should be allowed to jump. I’ve put these together in the following
diagram:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 29
If we just check that the Jump axis has been pressed, we can
make our player jump like so:

Of course, this is an incomplete implementation, as we are not checking whether the


player is grounded or not. Also, if you keep the spacebar pressed, the player will fly
away!
We’ll now make sure that we can’t jump more than once on the same key press.
We can do that by using a boolean variable which we’ll use as a “flag” to indicate
whether we’ve jumped on the current keypress or not.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 30
This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 31
Is it really over? We’ll, there is just one last thing. See what happens if you jump
against a wall and keep on pushing towards that direction. Yep, you’ll get stuck
on the wall.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 32
This is caused by friction. This can be disabled so that our player doesn’t
rotate by creating a physics material. Physics materials allow us to give our
game object custom physical properties such as friction, bounciness, and how it
will behave when colliding with other objects. In your Assets folder, create a
subfolder called Physics Materials, and inside of that folder right click and select
Create – Physics Material, name it Player.

Give this new material properties as shown below, so that we don’t have any
friction. Make sure to select Minimum in Friction Combine. This means that no
matter what the friction is of the colliding object, the minimum value will be used
for physics calculations.

Select your Player prefab, in the Inspector look for the Box Collider component and
click in

Material. Select the physics material you just created in order to assign it to the
prefab.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 33
Now we are finally done with player jumping 🙂
Collecting coins
In this section we’ll implement coin collection. When the player collects a coin, a
sound will be played. In the next section, we’ll keep track of the score of the player in
an object we’ll call GameManager, which will keep track of game-level information
(score, high score, level).

Currently, if you touch a coin you’ll notice that they actually stop the player, they
are “solid”. This is not the behavior we want. We want to be able to detect a
collision between the player an a coin, however, we don’t want coins to affect the
velocity, or any physics property, of our player.
We need to make our coins a trigger collider. When another object collides with a
coins, a trigger event will be fired, and the physics properties of the object won’t
be affected, just as if you were going through thin air! Select the coin prefab, find
the component Capsure Collider in the Inspector, and check Is Trigger.

Do the same for the enemy prefab and goal prefab. We can now jump through coins.
We need to know “collect” these coins on collision, play a sound and destroy the
coins after collected. In

here

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 34
trigger collider

To detect whether the trigger object the player ran into is a coin we can give our coin
prefab a tag that identifies it. Select the coin prefab and in the Inspector, in Tag go
and select Add Tag. Create a “Coin” tag. Also, create “Goal” and “Enemy” as we’ll
use those later. After creating the tags, make sure the coin prefab has the Coin tag
in Tag on the Inspector (pick it from the list). Do the same for the enemy and goal
prefabs.

We can check the tag of the object we’ve collided with, and destroy the coin
we’ve collected by doing:

Let’s now take care of the coin sound. Create a folder in Assets called Audio, copy
the coin.ogg file provided with the tutorial source code (download at the start of the

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 35
tutorial or here). In the Hierarchy Window, right click and select Audio – Audio
Source, rename it to “Coin Audio Source”. Select the newly created object. In the
Inspector, drag the coin.ogg file to AudioClip.
Uncheck the box Play On Awake so that the sound doesn’t play each time the
game starts.

We need to know be able to pass this audio source to our player, so that it can be
played each time a coin is collected.

Inspector

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 36
Now drag and drop the coin audio source object into the Coin Audio Source field in
the player prefab’s Inspector, Script component.

Game Manager
Most games have some sort of high-level parameters and operations, such as
resetting the game, managing game over, number of lives, current level, options, etc.
In our game for instance, we want to keep track of the player score, the high score,
and the level we are in.

To keep track of these things, we can create an object that keeps track of these
things and helps manage it it all. We’ll call this object the Game Manager.
Something we know for sure about this Game Manager object is that we’ll only
want a single instance of this object to exist at the same time. In computer
science terminology, we want this object to be a singleton.

Create a script and call it GameManager. The following code will help us keep
track of the score.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 37
To actually have this script in our game, create an empty game object in the
Hierarchy Window, name it “Game Manager”, and assign our script to it.

Inspector
Since we are talking about the game manager here, it’s highly likely that we’ll
want to access it from many game objects, not just the player. Having to drag and
drop it each time can become time consuming. A different approach is to use a
static variable that can be accessed from anywhere in the code, without having to
declare public variables each time and drag and drop elements. This will also
help us enforce the fact that there will only be a single instance of the Game
Manager in our game (the singleton pattern).

The following implementation will provide all of the above. Plus, when we load
different scenes (game over scene, or other levels) the Game Manager is not
destroyed, which would happen by default. For more explanations see this official
tutorial and this tutorial on game manager.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 38
In our player, we can increase the score like so:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 39
We can now collect coins and see the increased score in the
Console!

What about keeping high score? That will be be quite


straightforward and can be done directly in GameManager:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 40
Of course, for now our high score updates just like our score.
This will be fully finished once we implement game over.

Enemy movement
Enemies will have an up-and-down movement within a range. We’ll make it so that
you can easily change the speed, initial direction and movement range. In the tutorial

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 41
we’ll only implement movement in Y, but you can easily modify this code to have
enemies moving in other directions too!
Start by creating a new script which we’ll call “EnemyController”. Attach it to the
enemy prefab. We’ll add some public variables, and also keep the initial position
so that we can move around it.

In each frame, we’ll do the following:

Calculate how much we are moving (distance = elapsed time * speed *


direction).

Calculate the new Y position (new position = old position + distance)

If we’ve passed the movement range, change direction The code of will then be:

Feel free to adjust the range, speed and direction of each one of your individual
enemies if you are not happy with the default values!

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 42
To detect enemy collision (for game over purposes!), add the following to your
player

if statement

Is Trigger

Multi-level game
In this section we’ll implement multi-level functionality. Each level will have it’s own
scene, and we’ll use the Game Manager to keep track of the current level, the
number of levels, and the level loading process.

Go to your Scenes folder (some people like to name this folder _Scenes so that it
shows first on the folder list), rename the scene we’ve been using to Level1.
Create a new scene by right clicking and selecting Create – Scene. Name it
Level2.
If you double click on the new scene, you will see that you are taken to a blank
scene. The easiest way to start a new level is to “copy and paste” the objects
from the Hierarchy Window of Level1, into Level2. In Level1, simply select the
objects you want, right click and pick “copy”. In Level2 right click in and pick
“paste”.

If you double click on the new scene, you will see that you are taken to a blank
scene. The easiest way to start a new level is to “copy and paste” the objects
from the Hierarchy Window of Level1, into Level2. In Level1, simply select the
objects you want, right click and pick “copy”. In Level2 right click in and pick
“paste”.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 43
Lets modify GameManager so that it can take us from one level to the next. I’ve only
implemented two levels for this tutorial, but the code is completely genetic – it can be
used for hundreds of levels if you so want!

We’ll specify the starting level, and the highest level we have in our game. If we
pass that level, we’ll send the user back to level 1. Let’s also add a method to
restart the game (used for game over).

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 44
This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 45
To detect when the level goal is reached. Provided you’ve checked Is Trigger on
the goal prefab:

If you try playing the game now and you reach the level goal,
you’ll see an error message in the console that will say
something in the lines of:

To add a scene to the build settings use the menu File->Build


Settings and add your scenes to the list (you might have to click
Add Open Scenes for each scene).

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 46
GameManager
statement (and of course, the rest of the Game Manager
implementation).

Adding the HUD


So far we have no idea what our score is. We need to show it to
the player. Let’s implement a very simple HUD where we show
the current score.
Start by adding a text element in the Hierarchy Window. Right-
click, UI – Text. This will create a Canvas element, with a Text
element inside. Rename the text element to “Score Label”. In the
Scene View, click 2D, select the text and press f. This will show
you the canvas location of the text label.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 47
When adding UI elements, a canvas is created automatically. A
canvas in Unity is a game object where all UI elements should be
located. Some UI elements such as buttons handle user input,
for which the canvas provides event system support, for which
an EventSystem object was automatically created in our
Hierarchy Window, as you can probably see. You can read more
about the canvas in the docs.
Drag the text label to the upper-left area of the canvas. Select
the canvas object and find the Canvas Scaler component in the
Inspector. Change UI Scale Mode to Scale with Screen Size so
that the whole canvas scales up or down depending on the
screen size. In this manner, the text label will always stay in that
relative position. Set the Reference Resolution to 1024 x 576.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 48
We’ll now import a much nicer pixel art font to use called Press
Start. Create a folder called “Fonts”. Assuming you’ve
downloaded the tutorial files, copy the files prstart.ttf and
license.txt

(both located in Assets/Fonts) into your Fonts folder. Make sure


to read the license file which covers how you are allowed to use
this font.
Now, if you select Score Label, find the Font field and click on the
circle next to it, you’ll be able to select our Press Start font. Set
the font size to 32.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 49
We can now see our text in this pixel font! However, it does look
a bit blurry:

This can be easily fixed by making a change in the Import


Settings of the font. Go to your Fonts folder, select the font file,
and in the Inspector, change Rendering Mode to Hinted Raster.
Press apply and you are pixel crispy good!

Before we move on to the HUD functionality, feel free to change


the font color or style (I’m changing it to white).
We’ll create a new object that will take care of managing the
HUD. Create an empty object called Hud Manager. Create a new

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 50
script and name it HudManager. Drag this new script onto the
Hud Manager object in the Hierarchy View.
The HudManager script needs to be able to access the text label
we created, so that it can change it’s contents. This will be added
as a public variable. We’ll give it a public method called Refresh,
so that we can trigger a HUD update from anywhere in our code.

We start by importing the UnityEngine.UI namespace so that we can easily


access UI- related functionality

Create a public variable of type UnityEngine.UI.Text for our score label.

We’ll refresh the HUD on the first frame of the game, to show the initial score.

The Refresh method modifies the actual text content of the score field. Notice
how we can easily access the current score in our game from the
GameManager.

Make sure to drag the Score Label object in your Hierarchy


Window to the Hud Manager object, so that it knows which text
element to modify!

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 51
The last bit missing is to actually call this Refresh method in our
game! We’ll do this in our PlayerController. Let’s refresh the HUD
at the start of the game (on the first frame), and every time the
player gets a coin.

In order to be able to access the HudManager from our


PlayerController, we’ll add a public variable:

Let’s refresh the HUD upon first frame:

And every time we collect a coin:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 52
Make sure to drag and drop the Hud Manager object onto our
Player object. To make this work multilevel, simply copy these
new objects (canvas, HUD manager) into each level, and make
the corresponding dragging and dropping so it all wires up.

Note: you could also take a different approach and incorporate


HUD management into the Game Manager, or create similar
type of object. There is no single correct way and this seemed to
be the simplest approach for our game.

Note 2: if you are an advanced programmer and don’t like doing


so much “dragging and dropping” I’d recommend reading the
Dependency Injection series by Ashley Davis. Keep in mind the
approach presented there is definitely more advanced.

Home screen
In this section we’ll implement a simple home screen. Create a
new scene in your Scenes folder and call it “Home”. Add it to

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 53
your Build Settings like we did before, make sure it’s at the start
of the list.

For the background of our home screen (and our game over
screen) I’ll be using the image that comes in Assets/Images. Feel
free to use that or any other image. Create an Images folder in
your project, and put the background image in there. The size of
the image is 1024 x 576.
We’ll create a text field like before (which will automatically
create a canvas). Inside this canvas, also create a new button
(UI – Button) and a raw image (UI – Raw Image).

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 54
The order in which each UI element is rendered on the screen is
that of the elements in the Hierarchy Window. If you want an
element to appear on top of everything, move it all the way down.
On the contrary, to have an element in the background, move it
all the way up. We’ll make sure the raw image is in the
background.

Select the Canvas, set the UI Scale Mode to Scale With Screen
Size, which will make everything look small. Change the
Reference Resolution to 1024 x 576.

Extend the corners of the raw image element to match those of


the canvas. In the Inspector, select our background image on the
Texture field (or drag the image file onto the RawImage object).

Rename the RawImage object to “Background”, the text to “Title”


and the button to “Start Button”.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 55
Change the font of Title to our Press Start font. Change the font
size to 48, color white. Move it around so that it looks nicer. You
can easily style the button too by expending it in the Hierarchy
Window, and editing it’s child Text field just like we did with the
title. This is what my home screen looks like:
The last step here is to make our button work and actually make
the game start. Create an empty object called UI Manager.
Create a new script named HomeUIManager and drag it on to
the newly created object.

This new script will contain a single public method which we’ll call
StartGame (not to be confused with Start):

Select Start Button in the Hierarchy Window, find the component


Button (Script) in the Inspector. Where it says On Click() click the

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 56
plus button and find the public method we just created
(StartGame). After this, your homescreen should work is you
press play!

Game Over screen


For simplicity, we’ll make the Game Over screen will work very similarly to the Home
screen. Start by creating a new scene called Game Over. As a starting point, I’d
recommend copying and pasting all the objects from the Home scene. Rename the
text to “Game Over”. Add the scene to the Build Settings as we’ve done with the
previous scenes.

We’ll add 4 additional text labels. Give them style and text values as shown
below (enter any number for the score and high score):

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 57
The following functionality needs to be implemented:

Restart the game when Play is pressed

Show the score and high score

For that, we’ll take a similar approach to what we did for the home screen. We
already have a UI Manager object in our Hierarchy Window (provided you copied
and pasted everything from the Home screen). We’ll use this object, but with a
different script, so remove the HomeUIManager script component in the Inspector.

Game Manager
GameManager

Create a new script called GameOverUIManager. This new class will have public
variables so that we can pass on the text elements where we want to show the
score and high score. Also, it will have a public method to restart the game,
which we can use in our Play button.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 58
You should be seeing zero values on the score and high score fields. Also, if you
click on Play that should take you to Level 1.

namespace so we can easily switch between scenes:

Then send to Game Over:

Finishing up

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 59
If you’ve followed along all the way here I have to say well done!
We’ve already covered a lot of ground and all the concepts we’ve
covered here apply to pretty much all games.
You are definitely on the right path if your goal is to make games
with Unity.
The last part is to actually build your game, so that you can run it
as a native application on your computer, whether you are on
Windows, Mac or Linux (that is the magic of Unity!).

Build the game by going to Build Settings, selecting PC, Mac &
Linux Standalone. I’ll select Windows as my target platform and
x86 as the system architecture, then click Build and Run. Make
sure all the scenes are showing under Scenes to Build.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 60
We’ve built our game assuming a screen ratio of 16:9 (that is the screen ratio of the
background image we are using), so we want to make sure only this ratio is
supported. Otherwise, in some screens people might see the area outside of our
background. Go to Player Settings, find Resolution and Presentation – Supported
Aspect Ratios – uncheck all but 16:9.

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 61
Choose a destination and a name for the executable file (I’ve called mine
game.exe). Choose a resolution and whether you want your game to be
windowed or not. You can disable this window in Player Settings – Resolution
and Presentation – Display Resolution Dialog.

And we are done! We can now play our newly created game. Good job making it all
the way here!

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 62
Word Cross Puzzle Documentation
Thank you for everyone who opened this ebook. Please feel free to ask me any
question about Game Development.

Download Game Source Code : https://rb.gy/s8xty1

💡 You can publish this game in any apps store including Google
Play, App store and other mobile stores.

Overview

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 63
Word Cross is ready to publish game templates of the most popular genre for mobile
platforms. You do not need to know any programming language to configure and use
it. It is very easy to fill it with your own tasks, make UI changes, and start to gain
experience in promoting your game and earning money.

Requirements
Unity 2020.3.14f1 or higher
( How to download Unity : https://www.youtube.com/watch?v=hRKcbwUzjuQ)

The template works best with the version used by our developers (Unity 2020.3.14f1

So if there are any issues with your newer version, please let us know. If we can’t
solve them, you are required to use the same Unity version with us.

How to import projects ?


Open Unity 2020.3.14f1 , click “Open project” → Choose “WordCross_v1.0”
folder → Wait until the import process completes.

Double click on Main in the Assets/WordCross/Scenes folder → click Play


button.

How to build for Android (64 bit complaint Google Play)


Refer tutorial from Unity for more information :

https://learn.unity.com/tutorial/publishing-for-
android#5ecf930aedbc2a002088a2cc

Click File/Build Settings : Choose Add Open Scenes, Android Platform -> Click
Switch Platform and wait until the import process completes.

Go to Player Settings and look at the Configuration section:

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 64
Scripting backend: Set to IL2CPP

Uncheck x86

Building for Android sometimes gets errors because of your environment. If you
encounter any errors, please make sure that your building environment is set up
correctly by creating a new empty project and then build. If it failed to build, then you
have to find a way to fix it.

If you succeed to build an empty project and still encounter error when building
my project, then:

Use the same Unity version with us (Unity 2020.3.14f1)

Feel free to contact us

How to change package name


Click File/Build Settings : Choose Player Settings . On the Inspector panel, click
Other Settings. And edit your Package Name

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 65
How to CONFIG (Admob, In-app purchase)
You are required to achieve this before doing anything else. This is where you can:

Edit game settings (Admob, In-app purchase, …)

To see the CONFIG Mobile ads, please click on the menu


Dotmob/Mobile Ads → look at the Inspector at the right side

Change your Admob id and click Save

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 66
Click Menu Assets/Google Mobile Ads

Note : You can check Admob works in 2 ways:

Use your admob id (authenticated account) and add test devices:


https://support.google.com/admob/answer/9691433

Use Google's Admob test ID: https://developers.google.com/admob/android/test-


ads

Alternatively, you can check including the required Google Play dependencies in
your Unity project. Ensure the required AAR and JAR files are located in the Assets /
Plugins / Android directory. You can perform dependency resolution by selecting
Assets -> external dependency manager -> Android Resolver -> Force Resolve in
the Unity editor

IAP

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 67
https://join.skype.com/invite/vJCdfSUWab41
IAP is setup using the IAP Settings window which can be opened by selecting the
menu item Dotmob -> IAP Settings (Or clicking the button on the IAPManagers
inspector).

Enable IAP
To enable IAP first you need to import the Unity plugin from the Services window.
Open the Services window and turn on IAP then click the Import button:

Once it has finished importing you can open the IAP Settings window and click
the Enable IAP button which will enable the code in the project

NOTE : Please use IAP version 2x

How to change YOUR_ONESIGNAL_APP_ID

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 68
Replace "YOUR_ONESIGNAL_APP_ID" with your OneSignal
app id in MainScreen.cs

How to get OneSignal APP ID https://www.youtube.com/watch?


v=I6yrKAhMs3U

Level Editor Tool https://t.me/bhanuvardhan


To open the window, select the menu item Dotmob/LevelEditor

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 69
The file that contains all the words in the game. This is the game's
Word File
dictionary and should contain all possible words, each on a newline.

Enables batch generation mode. Batch mode is used to created multiple


Batch Mode
randomly generated levels.

The ratio (rows by columns) that the grid should attempt to match. This is
Preferred Board used to generate grids that best match the ratio to be displayed in.
Ratio (Example 1x1 would create mostly squared grids where as 1x2 would
created more portrait looking grids)

The way the grid is generate is by generating a bunch of random boards


Max Boards To then picking the best one based on the Preferred Board Ratio. This is the
Generate maximum number of boards that the algorithm will generate before
terminating.

Sets the number of letters for each level. This is the number of letters that
Letters In Level
will appear in the letter circle in the game.

Number Of
The number of levels to generate.
Levels

Length Pick Determines the behavior when choosing words for a level. • Random
Type means length is not taking into consideration when choosing a letter. •
Longest First mean the longest possible word will be chosen first. •

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 70
Shortest First means the shortest possible word will be chosen first. •
Distributed Longest First means the longest word will be chosen first,
followed by the second longest, then the third, etc • Distributed Shortest
First is the opposite of Distributed Longest First meaning the shortest word
is chosen first then the second shortest, all the way to the longest word at
which point it wraps back to the shortest.

Determines the behavior when choosing words for a level. First Length
Pick Type is used to get a list of words by length to choose from then Rank
Pick Type is used to choose which word from that list is chosen. • Random
Rank Pick Type means a random word is chosen form the list. • Most Common First means
the word with the least Rank value (Appears first in the word file) will be
chosen. • Least Common First means the word with the highest Rank
value (Appears last in the word file) will be chosen.

This section is used to export the level when all the desired words have been added.
To set the Output Folder simply drag a folder from the Project window in Unity into
the field. If a Filename has not been set the the id of the level will be used.

How to debug disable level Locking, Remove Dotmob


text

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 71
How it’s Possible ?
We guide you with very simple steps:

1. Get ready to publish games Source Codes (link)

2. Modify few key parts

Change Package Name

Change Logo

Change your Admob (ads integration ID)

3. Generate signed AAB file

4. Publish it in Google Play store and at many more app stores.

🛰 Ready to publish games source codes


reach out to me get 1500 High Quality

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 72
Unity Games Source Codes in just $149
Source codes list includes most Popular Games

Subway suffers

Candy Crush

Multiplayer Shooting Games

🤑 All the other categories of 1500 games sources codes in just $149 🤑

⚡Highlights ⚡
📄Clear Documentation for Setup (installation)
🤑 10 Ad Networks Integrated (Banner, Interstitial, Reward Ads)
Admob

Unity

Facebook

Iron source

Applovin Max

Adcolony

Vungle

Chartboost

MoPub 10.Heyzap

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 73
🔌🤑 Mediation also supports

In-App-Purchase Items
🔌
🤑 Support Android version 12
🤑64 bit Supports
🤑 Unity version 2020.3.13f or Latest
🤑Get all download links document in one minute
🤑 Dedicated Support for any issues

Reach us here
Telegram : https://t.me/bhanuvardhan

Skype : https://join.skype.com/invite/vJCdfSUWab41

This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 74
This Professional's Game Development Guide (Theory + Practical Unity Game Source Code) is perfect for… 75

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy