Adding and Managing Assets in Unity 3D
We see that our game looks pretty empty right now. So let's fix that. Grab an image that you would want to make your player. For example, we will be using this happy little star.
We have Mr. Star here on our Desktop so that we can easily access him. To add him into Unity, we will simply drag and drop the image into our Assets.
What we've done so far is just added the Star image into our project, but not into the current scene. To add it into the scene, just drag and drop the image from the Assets view into either the Scene View or the Hierarchy (Objects added in the Scene View get added to the Hierarchy automatically).
Objects that you add as images are stored as sprites when you're working in 2D. Sprites is Unity's way of remembering that you're using these images to work with them in 2 dimensions, not 3.
You've added just one image, and you already must have noticed quite some changes in different views in the Unity window. First of all, and what may seem to be most noticeable, is that the Inspector View is no longer empty with options such as, Sprite Renderer and Transform listed below. These are called Components and they're important.
You see, Transform is a property of any object in Unity which stores some of its most basic data. What falls under basic data?
- Every object has a Position.
- It has a Rotation angle.
- It has a Scale Factor.
These are the values which tell Unity where and how exactly an object is positioned in the game world. Try changing the X
, Y
and Z
elements of these properties to different values to see what happens.
Sprite Renderer is a component which works with how your sprite (that is, your image) is handled on-screen. It has a few properties like the image to render, the color of the image (white means the image is unmodified), flips, and sorting layers. For now, we don't want to change anything around in the Sprite Renderer, so let's leave it as it is.
If you click the Play button now, you'll see that the image you added is now visible in-game! Woohoo! But, there's a blue background that you don't quite recall adding. That's because that background is added by the Camera in the scene. If you want to change that background color, simply click on the Main Camera in the Hierarchy, and then change the background color by clicking on the Background property for the Camera component in the Inspector.
So far, we've only added one asset. But as your project grows and gets bigger, and you add more and more assets, it may get difficult to manage all your assets. That's why making sure your assets are properly organized from the start reduces a lot of future headaches (Trust me, I've been a victim).
You can organize your assets into folders, right click anywhere in the Assets section, and select, Create → Folder.
How Unity Works?
Let's stray away from working on Unity to dive into understanding how Unity actually works with games below the hood.
Imagine you're a completely normal person. You're not a game designer or anything, you just go about your daily business.
Imagine you go to see a play one day. You buy a ticket, you sit down at your seat, maybe buy some snacks on the way, in a mood to enjoy the evening.
Here's where the real fun starts. If its a play, what kind of things do you expect from it? Surely there's a stage on which everything happens. Also, a play isn't a play without a decorated stage and people moving on it, right? Who would want to stare at an empty stage for an hour, much less, pay for it? You could say there's a lot of stuff on the stage, a lot of objects.
Most plays are usually divided into scenes. There could be a scene of a dark forest with huge trees and a lake with fairies around. There could be another scene of the inside of a castle, with gold paved everywhere and chandeliers hanging from the ceiling. Where I'm going with this is, there are different scenes in one play, where the objects on the stage could be different or even the same (One could use the same cutout of a rock in a mountain and near a mine)
Unity is simply one giant stage play. Everything in Unity happens in scenes. Your game's title screen will be a scene, the end credits will be a scene, your game-play will happen in a screen (or several of them), heck, even your options menu will be a scene. Every scene in Unity is made with objects, much like everything in a regular stage play. You're arranging cardboard cutouts in a stage play scene, whereas you're arranging things like audio sources, light sources, players, cameras and maps in a Unity scene.
Actors in plays generally have scripts that tell them what they're supposed to do, act and say at any given time during the play. We can call the actors objects too, right? Human beings are also objects, after all. Similarly, some or all objects in a Unity scene may have scripts that tell them what to do, when to do it. Making these scripts, involve writing code (Usually C#
or JavaScript
) and attaching them to the objects you want the code to affect. For example, if we have a spaceship in our scene, we would write a piece of code for moving it around with the arrow keys. We would save that piece of code as a script, and then attach that script to the object that is your spaceship (Everything in a Unity scene is, in some way or the other, an object, remember).
This is what Unity is all about, really. You're just making one, giant interactive stage play. As much as you're becoming a game designer by learning Unity, you're also becoming a stage play coordinator! (Well, not really)