Unity introductory tutorial P.1

Hello my friends! This tutorial was requested by a cool foreigner follower in the facebook page! He wanted to learn Unity with something written and clear english.

I emphatize with him, because the video tutorials tend to be difficult to understand, specially for non native english speakers like us; also, it´s weird trying to pause the video each time to know what to do and if there is code involved, is frustrating trying to see what it´s written in small letters!
So here we are, with this comprehensive serial tutorial I´m going to be publishing each week or so.

I can´t assure a regular basis (unless a legion of followers ask me to do so gifting me with lots of likes and shares!), but here you have the first part, and this will give you a whole understanding of the Unity editor, for setting up your scene.

The next tutorials will be about codification, I will have to indulge myself in nasty stuff like the basics of c# and Unity API, so that you can learn to code from 0 previous experience!
You just need the game engine Unity 3D 5x installed on your computer. In my case, I have 5.5.0f3, because from there on the WebGL is more optimized than in previous versions, go ahead and download whatever you may want.

You need to make an account to download it and install it, once you do that, you can install it in whichever computer you may want. You can even install it in various computers simultaneously, I have never had problems with that.
So go ahead and create your little indie company with friends and such, or whatever you like, if you don´t have more than certain amount of people working for you, and you don´t earn more than certain amount of money, you won´t need more than the Unity personal edition.

This is also true if you don´t need the advanced functionalities of the engine, I don´t use them, and don´t have any plans on them yet, so if you are the same, stay with the free version, otherwise, serve yourself with a paid version.

Without further addo, Let´s begin the tutorial!!

Here we have the main screen of unity, i will save you the mindbogging task of memorizing the technical names of each section of the unity interface, I don´t even remember all of them, I will just name them like I know them, by the name showed in their labels.

This is called the Unity Editor, there is another screen you can be working with, called the code editor, if you have previous experience with that, you may know there are lots and lots of code editors out there, but Unity comes with its very own integrated editor, the Monodevelop.
I won´t indulge too much on this topic, because it will be explored in next tutorials, but just so you know, you can change the predetermined code editor to whatever you may like, visual studio, notepad++, whatever.
I keep mine as monodevelop, its more practical (I don´t have to install third parties) and it comes with integrated sintax corrector, that´s useful to save you time editing code. So let´s forget about this until next time, and focus more on the Unity Editor!

So we are going to learn Unity by example, in this case, by the request of the public, we are going to make a simple but cool shooter genre videogame, with a third person fixed aereal camera and 2d graphics, because those are easier to manage and produce by yourself. ´
If you don´t feel like making your own assets (you lazy non artist… kidding!Hahaha), I uploaded the simple but usable assets I use on this tutorials in my Itch.io page.

I won´t be sharing the Unity example scene as of yet (until the next tutorial!), because I explain how to set it on this tutorial, so make the effort to make it for youself.
For now, you can get the images I made for this, just follow this links…

Go play the live Demo and download the assets here…

Live Demo Unity introductory tutorial P.1

First of all, you need to plan out your videogame, I already set the technical propierties of it. I´m going to include in this tutorial some basics of game design, on a cool book called Level Up by Scott Roger, I strongly recommend you to check it out, specially if you just begin with your videogame making career.

Level Up presents you with this cool concept of the Game Design Document, or GDD for short, basically is the bible of your very own videogame, it has all the information you may need to make it real and true to your vision, very useful if you are working on a team, or have bad memory, or haven´t decided all the aspect of the game yet. To flesh it out completely, you can take this as a guide and release your imagination.

The GDD begins with the cover of your game, but we can leave that out for now, because we haven´t yet decided the rest of the game, LOL.
Name your game, this will help you to name your Unity project too, I called mine Unity 3D beginners tutorial, because that´s what it is, but you can work with whatever you like, like rapid shot or whatever.

Next, establish the objectives of the game, in this case, something simple will work, like shooting down all the enemies without dying in the way!

A quick story overview can help:
-the setup, how do your player will begin the game, what are the conditions that will trigger the game, the story that will put into motion the actions the player must take to accomplish the game objective, in this case, it will be something simple like the character Gun McShooter goes outof his house, then violent people start appearing around, gunning for his head for no apparent reason. He, being the badass he is, won´t stand around allowing others to shot him down, he will fight back, thus beginning our story!

Next up, you need some narrative contextual locations, in my case, I will keep everything in the same scenario, some kind of old western town, with some obstacles, barricades, windows, doors to shoot from and maybe some prop animals. Everything can come into play as props and modify the game mechanics.

Finally, we have the final! Decide whether the game ends with you killing everyone or beating all the levels, you can finish with whatever objective you may wish, in this case, the levels will be the augmentation of gameplay difficulty, more enemies, more weapons to them, and even could be more Artificial Inteligence, but in exchange, the player will have more potent weapons, more resources, even equipment and stuff. It will end after certain levels, because I´m not aiming for an endless increasing difficulty level, so that´s it.

The rest of the GDD talks about game controls, technical requirements, some front end for the game (merchanidizing and stuff), opening cutscene (the introductory information and logo splashscreen), some other little interface and ambientation details, game flowchart (in case you have various level scenes and interfaces, which this simple game won´t have because it´s just an introductory tutorial, that´s way too advanced!), game cameras (which, for now, we will just say is third person and aereal).
Almost all this stuff pertains more to the next tutorials on scripting, because that´s what will allows you to add those functions.

For now, we will settle just with the aesthetics and layout of the scene, but you can begin deciding those stuff in the meanwhile. if you don´t know what those mean, you can search for the book if you wish, or wait untill the next tutorials are up, they will cover all that on details while developing it for the game, so stay tuned and like me for more content!
Now that you have taken some basic decisions for the game, we can play around with the Unity editor, let´s do it!

First of all, you need to identify what´s a Unity Scene and what not, a Scene is where all the things conforming the game will be added, placed, distributed and accesible from your game. Whatever isn´t on a scene, can´t be used during gameplay, unless you have a special script that allows you to do so.
Think of a scene as the level of the game, you can have as many scenes as levels, unless your levels are those of increasing difficulty and stay the same in terms of background, props, etc. Or you can change enviromental stuff during gameplay through scripts, and even though stay on the same scene, but that´s more tricky to do.
Also, changing scenes allows the game to refresh the scripts, the broken, missing or death things on the game (like enemies, props, etc.) and more order for your levels.
You can set a scene with a western thematic, and other with a subaquatic thematic, have all the enemies, NPCs, props and stuff properly added to both, each one exclusive of them, control the flow, the memory consumption and the gameplay for them, and when you want something new, just change scene. Such is the power of this system.
You can see the scene elements in the scene Hierarchy Window…

You can modify the scene in the Scene Window…

And you can see how the scene is setup in the Game Window. By default, each of them comes open up for you to easy access them.

An important detail is to always save the changes you make to a scene, name it and store it in a proper carpet so it won´t get lost among the other asset files of your game.

Now that we are playing with the different windows on the Unity Editor Interface, let´s talk about it. I strongly recommend you to customize the graphical interface of the Unity Editor by checking out this section here…

Which is the layout selector? What is layout? You may ask. Well, simple enough, you can change the way editor windows are placed around the way. But what are those editor windows I´m blabbing about? Well, take a look at this other menu…

The window menu, which is the displayable list that allows you to chose which window to open, a window is a visor to certain propierties of a given Game Object on the scene, it will allow you special features classified by the designated name.
I have my own custom layouts (you can see them by the name Mary, LOL!), each one I use to potenciate my workflow to a more eficient experience. For now, you may have something like this…

go ahead and play around with the layout, you can drag and drop windows as you please. My main layout (called Mary Code), is the one i use when I´m beginning a new project, I can easily access my assets (project window), edit my hierarchy, both at the right side, because I´m right-handed and occidental, so watching content from left to right is natural for me. I have my scene besides the game window, so that I can switch between the two during play test and have them ocuppying the most available space (great for visualization). In the bottom I have debug mode Inspector (click on the little three bars of the window and select debug).

This will help you see those script variables not accesible from inspector (you have to label them public for them to be accesible, otherwise, this is the only way you can see them).
Some things need to be hidden so some dummy artist playing around with the scene and gameobjects won´t break your delicatetly measured codes and such, others are internally modified by the code and you won´t need or have to modify them, but is important visualize them so you can know what´s happening during gameplay.

Next is the console window, it shows you after each play test what happens with the codes, the bugs, the advertencies (something that is not as right as it should be!) and some other thing you tell the code to show for you (with the method debug, we will see some of it later!).
Finally, we have the most important part for modifying gameobjects! The Inspector window, here you can see all the propierties of the objects you have in whatever place of the Unity Editor, an asset, a gameobject, everything you can access and modify.

If you want to, just go ahead and copy me, I now you want to xD

Next one, you have to be familiar with GameObjects, which are the game elements inside Unity so that you can edit them and make a game, just think of your playable character or whatever else you may want inside a game, everything will be a GameObject. The things that will not be GameObjects are materials, textures, videos, codes and external resources, called assets, which you will put inside the game objects, but you can´t have by itself a texture around your game, it will have to be attached to a plane, a cube or something.
Our little game will need a nifty floor where everything will take place! Let´s see how to add GameObjects to the scenes. Just click on the Create menu over the scene hierarchy (that place where your GameObjects will be listed after you add them).

Let´s focus on a special GameObject for now, the Terrain, select it and you will see this in your scene…

You may not know what it is at first, it looks so alien from that perspective, but let me share you a secret, the Unity Editor can be navigated. Can you see those controls in the left superior corner?

If you select the first one (shaped like a hand), you will see the mouse pointer change to a hand, if you click and drag across the editor you can pan the view, that way, you will see more of what is in there!

For more control around, you can zoom in or out by pressing down Alt and the right button mouse, and rotate the view with the right button mouse alone. Zoom out until you can see the extension of your terrain, mine is enormous because of a previous project or something, you can see the real measures by left clicking on the Terrain GameObject and checking on the inspector window.

You can see under resolution the values that will give the real dimensions to your terrain. If you are planning for a game with a vast land to explore, put some higher values here, but because I want to keep things simple, I will change it to something like width 100, lenght 100 and height 50, height will allow you to terraform it with the brushes we are going to use next, forming valleys and cliffs. Once you make some changes on the first two values, you will see the terrain changing its real dimensions, but for height, only once you edit the terrain changes will be noticeable.

Now that you have a less resource consuming terrain, let´s edit it! You can see here there are a section labelled as terrain, this is called a component. This component thingy is an script the Inspector Window can show you so you can modify it.
Some scripts are internally controlled and you can´t open them on the Script Editor to modify them, some others were made by you! or someone else, but the important thing is that you can open them and modify whatever you want.

If you take off a component, the gameobject will cease to function in whatever that component allowed it to do. For example, take off terrain component and it would no longer be a terrain, it will be just a plain boring plane, but no, because it doesn´t have that component, it will be an empty gameobject, nothing but an ubication on the space (which is useful for other things, but not as a floor!).

The funny thing about components is that you can create them yourself and make your own custom gameobjects! Also, those width, height and lenght fields we modified are called propierties, they are internal variables of those scripts, if you make your own component (codifying a script), and put some public variables, those will be treated as propierties and can be accesible through the Inspector, that´s so beautiful!

So, for now, we will concentrate on the little labels with icons under terrain component. Those contain tools for editing the terrain, try out the one with the brush on it. This will allows you to add a terrain texture to paint over the floor and make it stop being so whitey!

First, you need a texture on your assets. Let´s click on the create menu of the Project window.

Chose the folder option from the displayable menu, name the folder as whatever you can use to identify what it contains (in this case, textures is fine). You can do this for every type of assets you insert into the editor, this way, you can have them properly ordered!

And add by drag and drop (over the folder, you have to minimize somewhat the Unity editor to do se) the terrain texture.png I include in the assets folders you must have downloaded from Itch.io! If you have a little +arrow below the pointer while doing this, you are doing it correctly and when you release the mouse button, the archive will be added to the chosen folder.

Chose Edit textures, then add texture, and in the displayed window, chose normal and select the texture you uploaded, then select Albedo and chose the same. Modify the tiling as you wish (if you put the dimensions of width and lenght, it will extend all over the terrain without making a tiled floor) and then click Add.

You can play around the rest of the tools, most of them are self explaining, I will leave them for now for simplicity, but feel free to experiment, it will help you learn! Also, you can add as many textures as you may want, paint them over the terrain and have a diverse field, have fun!

Now, we have to set up the camera so it is as we wish it to be, by default, Unity always places a helpful main camera on newly created scenes. You see, a scene can´t be played without a main camera, how do you know it is main? You may want to look closely here…

That little Tag field works as a label to identify gameobjects from others. Some internal Unity scripts (predetermined components) need them to work properly. By default, the engine always checks on the MainCamera Tag for a camera that will help the player visualize the scene.

Through scripting you can change which camera is the main (thus having many cameras with different modes, like and overhead camera, a third person camera, first person, rotational camera, etc., in the same game, changeable with the click of a button!).

Also, other non-main cameras can help you set special objects for visualizing different things! (like having a TV screen, a videocamera, a mirror, retrovisor, etc.).

So whenever you set a new camera, be sure if it´s main or not and stablish the proper tag to identify it, and also, check for duplicated AudioListeners components, all main cameras should have it, but just one per scene or there will be errors with the audio, and you don´t want that!

There are other tags for other purposes, you can even add new tags for your own purposes, but let´s leave them for some other time!

For now, we can see our Main Camera is off objective, we need it pointing towards the terrain from the sky, so let´s change that!

With the camera selected, click on the second icon where the pan (hand) icon was, the one with the cross shape, this will activate the displacement gizmo on the camera.

If you click and drag one (or a combination of them by their middle square controls) of the three available colored arrows, you can move the camera around in relation to the scene space, zoom out, rotate, pan or whatever you need in order to achieve a better view of the terrain, and place the camera just in the middle of this floor.
It will be changed later, in relation to the playable character, but you will need a script to do so. For now, we will use it as an easy visor to know how the scene is looking up as we place the other stuff on it.

If you need help in settinf up your view with the pan, zoom or rotation tools, just use the gizmo with colored cones and a little cube in the middle. If you have ever used any Autodesk product, this have the same function as the navigation viewcube, try it out, it´s funny!

So now, we are where we want the camera to be, but there´s a problem.

By default, Unity always places the camera facing towards the front view, but we want it to be facing towards the top view! Let´s change that, chose the next icon with the circle arrows. The gizmo will change to something like a sphere, made with colored strings.

Why all these gizmos have the same three colors!? That´s like, so weird, isn´t? No! It´s the standard (or something like that) color code for the three dimensional axis in a threedimensional virtual world (many 3d modelling softwares have it look around and find them all!).

If you don´t know which color does what, just look at the cube with the cones gizmo in the right top corner. We need to rotate the camera 90 degrees in the z or x axis, or at least, that´s what´s labeled in the local transform of the camera, which is all that matters!

If you want more control while modifying one of those propierties of any given gameobject, you can refer to the Inspector window, any gameobject must always have a Transform component, try to change the propierties in whatever field you may want, for this, you need to change the rotation propierty, whatever can work, just experiment around…

When you finish setting up the camera, you can now add the player!
Let´s get our hands dirty with the other gameobjects Unity gives you by default.
There´s nothing bad with using the default gameobject Unity comes with, you can always modify them to your needs, knowing how differentiates a pro from a no0b! Also, knowing what to use in which case.

You can see here there´s a create 3D object option. Maybe you want to experiment with these, just to know how does it feel, maybe nice! Who knows?…. But wait!!!! we are making a 2D game!! We have to use only 2D gameobjects, right? Well, maybe, maybe not! How am I supposed to know? Oh, right, I´m making this tutorial..
So let´s see….

3D gameobjects gives you more options and possibilities, which is always nice! What do you need? What can you use? Well, for instance, you need a character gameobject. How does it works? You need something that can move around, hold guns, shot and hide behind objects, also be affected by enemy attacks and not go through the floor!

Uh? What did I say about going through the floor? Yeah, you are basically a ghost here, when the game begins, if you have mass, you will go through the floor, unless you have collision too. But what am I talking about, you may ask? You are just a beginner baby and haven´t touched a physics book in your life!! Hahaha, kidding.

Well, you know that physic concepts mass, gravity, impenetrability and such? All of them apply here, so if you have basic understanding of it, good, I go through with just a vague concept of it all, the optimum would be for you to know equations and stuff, but Unity can do a lot of those for you…. unless you need something advanced!

But since we are just beginning here, you needn´t worry yet!
So let´s see what those sprite thingies are, chose it and explore it with the Inspector…

For now, your sprite is invisible, it doesn´t have a texture, and you can see it only has a transform and sprite renderer components. Sprite renderer doesn´t have mass, nor collision, it won´t be affected by gravity either, because it´s basically air! This sprite gameobject will only serve as a container for a 2D gameobject! Funny, but efective for a 2D game. Let´s chose our character sprite and add it to the project, then to the sprite renderer…

Aha! You have discovered it can´t be added to the sprite renderer!! It gives you a black blocked circle, right? I fooled you, you first need to click on the texture, there, on the texture type dialogue, you can see the Sprite (2D and UI) type, right? Click on it, you will need it!

You don´t need to change more than that, just click on the Apply button at the bottom of the Inspector and you are good to go!

Now the sprite has a little displayable arrow and inside it, a square thingy named like itself. This is good, if you have multiple sprites on one image (like a sprite sheet for animation), you can split them up with the sprite editor (inside the same options I told you not to change!) and they will be listed here for you to see how they split and if you need to make changes.

For now, we just need this one image, we are not going to make more changes on the character until is time to learn animation on Mecanim. What´s Mecanim? Well, that´s how Unity called its new animation system (the most recent, at least, it has some time now…), yep, they are weird like that!
But it´s a cool graphic codification animation system, easy to use and understand, really, I practically learned it by myself (after getting many headaches figuring out which is what and how does whatever!).

So, back on topic, we have just put our nifty sprite on the game! Yey, now drag and drop it on yur sprite renderer and you are good to go!
Now try rotating around it, you will notice it is just a planar image, perfect for a 2D game with little resource consumption and such.

Well, but you can see the perspective is wrong, I did the sprite wrong, I do know nothing about perspective, me sucks T.T… no, wait!! Don´t blame this on me! It´s your fault, yeah, you haven´t changed the camera yet. I said It was going to be an aereal camera, I didn´t say it was top-down, I hate those things, really. What´s the deal with just having a blob going around with the typical design overhead?

What´s so funny about that perspective!? It just looks like a hotcake with some bulbs on its head and a banana holding a sausage! I don´t know what that is. It´s a shame, my character was so beautifully designed, I´m crying tears of blood right now! T.T

Well, if you like that view, then change it to whatever you like better, it´s your decision, the important thing for you is to know how you want your game to be and stick with it.
And as for me, I already changed the camera, so don´t worry for me.

The good thing here is that the character was created in the same spot as the camera (if you had it selected when you clicked on create 2D gameobject sprite).
If your character is off, just click on the little cog under the transform of the camera, select copy component, then click the transform of the character and select paste component values, and automatically the two will merge in the same spot, that’s useful.
You can even use this to add the same component to a gameobject that don´t have it, but you need it to have the same values too. Remember this little trick in the future!

Right now, the character doesn´t have physics and can´t move, the camera won´t follow the character either, everything are dumb objects, this is not a game, it´s not even funny and I´m already bored, consider me out of this… Ups, this is my tutorial, I´m here, I promise.

Well, we can leave it for now as it is, but I will take you one level up (as the book! woah). Let´s add the physics control to the character, it will allow us to move it, interact with others, have friends, long lost loves and many other wacky adventures! Chose a capsule 3D gameobject while having selected the character…

It will add itself in the same position as the character (if it doesn´t work, delete the capsule, double click the character while in the scene window and try again), but also, it will have volume and color, it is real! I even took the care to tag and name it properly. No more invisible items, yey! But bad news, we don´t need it to be visible…

So, to fix this problem, go to the Mesh Renderer component of this gameobject and click on the little checked blue square, uncheck it and watch it disappear from the virtual world!
You may be wondering, another renderer, that´s weird, what´s a renderer! I´m so overwhelmed by all these new terms! Well, stop curling like a twerp in the corner, the renderers allows you gameobject to be visualized, renderize is to draw in the virtual world~

There are more renderers out there, like the skinned mesh renderer, which allows an exported 3D model to be drawn and all, but that´s way advanced now, and also, it belongs to a 3D game or one with 3D graphics involved. But don´t worry, maybe we can use 3D objects to simulate a 2D world.

You know, even when emulating a 2D world, there are times when stuff around needs to be 3D in order to be seen correctly from all angles. Since our camera will be fixed, which means, won´t rotate around the world or the character, just follow hi around from behind, having anything else besides a 2D character sprite is overkill, he won´t ever be facing at the camera.

And since this is a 2D game, if you want to have cutscenes with him facing at the camera (we can have them, but in later tutorials!), just add them as animations and reproduce them on tv screens, that´s all you need, and it saves you having to make more graphics for the characters.

In this simple tutorial game that´s allowed, because the flesh and the bones are how to use the program and basics of programation, not making the next final fantasy. But for your own advanced games, feel free to experiment with whatever you may want!

Well, now we have a physical body for our little character, you don´t need to move it from where it is, just in the middle of the character is fine. Later on we will experiment with this.
You can see it already has some shady thing called Capsule Collider, as the renderers, there are quite a lot of colliders out there, with different shapes (even a Mesh Collider perfect for its use with the skinned mesh renderer).
We won´t touch them now, and I will explain more about them later. Just know this will allow the character to interact with whatever else has a collider, cool, isn´t it?

But right now, it is not part of the character, so when we make it work with script, they will not be connected at all! Why is that? If you look at our Hierarchy Window, they are in two different places. What does that have to do with anything? Well, in Unity, things must be parented in order to work together or something like that, it all depends on the context. To fix it, drag and drop the character control over the character sprite, and that´s all, now character control is a child to the parent that is character sprite! Try moving around the sprite and see what happens! I went ahead and also parented the camera to the sprite, because that way, you won´t have to script it following the character around, it will follow wherever the sprite goes!

Another extra thing I want to teach you is about the camera, you can play around with the displayable menu under the camera component (which makes it be a camera, after all). There are perspective and orthogonal view type, chose whatever you please, then drag or type whatever field of view (perspective slider) or size (orthogonal field) you want.

Experiment around, try everything and learn by exploring!

If you have any question, don´t think twice to ask me here or through the facebook page. Have fun and go ahead and add more gameobjects with different shapes, or create your own props and place them around the field. You can use whatever image you find on internet, everything is flat, after all, just what you need!

Next time, we can get around making the character moving around, the essencial of any game, don´t you think? Or else, with what will you be able to play? Moving the terrain! Hahaha
One final tip, if you click on the little play arrow at the top of the editor, you can enter test play mode, right now there is nothing to play, but you can experiment with it. Don´t forget to save your project!

Published by

Mary D Kidd

Una misteriosa creativa dispuesta a dejar sus ideas salir y tomar control del mundo. Preparada siempre para innovar ;D

Leave a Reply

Your email address will not be published. Required fields are marked *

Transcribe Unity introductory tutorial P.1

Your email address will not be published. Required fields are marked *