Wednesday, February 9, 2011

Lights, Camera, Action!

Time to start our little game.

First off you are going to need to open Unity. Once your done give yourself a nice pat on the back. Step one complete!

Now we want to start a new project called "Overload". Click on File -> New Project. This opens the New project dialog. Find a place you want your ame to be located in. Make sure it's something easy like:

C:\My Games\Unity\

You don't something that is so hard to find you have to spend 10 minutes getting there because you will be going there a lot. Something like this is very, very bad:

C:\My Games\ABC\123\DoRaMe\Lalala\Unity\New Folder\WTFisThis\gameFold3r
In side this folder make sure to create a new folder titled "Overload", "Unity Tutorial" or something you will remember. Navigate inside this folder and click the Select Folder button.

 Now you want to select the components that you want included in your game. We will not be using any of the default things so leave them all unchecked for this tutorial. However if you are curious what this does then select the Light Flares option. This loads premade "Flares" that you can stick on lights (more on that later).

Now you should see a nice gray screen on the top left, a grayer screen on the right and another few panels below the big gray screen. You should also see some fun buttons on the top of the screens.


Now I'm going to tell you what each of these areas do. PS: I'm sorry about the color job. Apparently I didn't save the cool looking one so I went back and redid it. It doesn't look nearly as good... my bad.

  • Orange: This section is your standard buttons. File, Edit etc. You can change the Layout in Window and use the Game Objects and Components parts to add them to your game or object. Also the Assets menu will allow you to import and handle your games assets.
  • Red: These are your game testing controls. You have a play button (if clicked while playing stops the game), a pause button (guess what that does) and a step button. The play and pause are pretty easy to use. The step is harder. It runs a single frame of your game and then pauses it again. This is pretty much the "Hyper Slo-Mo" version. You can use this to debug or to see how your code works every step of the way.
  • Blue: This is the Game Screen. This window provides a view into the world of your game. While what you see here will not always appear that way ingame you will be using this screen to set up almost every part of your game. From level design to visual effects.
  • Purple: This will provide details on the Item selected in the Yellow section of the menu. This screen shot shows the script that the current file "FlightControls" contains. This menu is customized to the object selected.
  • Cyan: In this screen you see absolutely nothing. But if you select a graphic, model or material this will show you a preview that you can rotate and play with to see how everything works.
  • Yellow: The yellow menu is a list of all game Assets your project contains. This is your game. All the data (models, textures, scripts, worlds etc) are all located here. Needless to say this can get extremely cluttered if you don't organize it. How you organize it is up to you but I recommend keeping all objects, prefabs, materials, scripts and such in different folders. It makes things easier.
  • Green: This section is all the objects in your world. This gives you a simple display of all the objects in the game world. It is very handy when you start creating new objects in-game and want to make sure they go away (we will be covering this shortly).   
All right. Now that you know where everything is, lets make something simple.

You will notice that your game already has an object in it. The object titled "Main Camera". For sake of tutorial purposes we are going to delete that object. Click on it in the bottom left box. Notice that it will show a camera preview and four lines will come out of the object. These lines are the cameras sight lines. The Preview box shows a quick preview of what the camera will see when the game starts. Also notice that the inspector (right menu) is full of fun information that you don't understand. Fun huh? This displays the objects positions in space, it's rotation and scale (for camera's the scale means nothing). The other menus will be looked into in later tutorials. For now just hit the Delete key (NOTE: This is different than the backspace).

Now you can't see anything! Why did you do that! You can't have a game without a camera fool. O well, I guess your just learning. Let me help you fix that. Click on the GameObject menu at the top of the screen. Select Create Other -> Camera. This will make a new camera and select it for you. Notice the objects position is some crazy coordinates. Lets change that. Set the camera position to 0,0,0 (X,Y,Z). Now for fun lets change the camera's rotation. I'll let you choose how you want to point your camera but to do it we will not be typing it in. See those 4 buttons above the Game View? The Hand, The Compass points, The rotating symbol and the scale symbol. Choose the one you think will work and watch as your camera is surrounded by orbs. You can click on these and drag to rotate your camera to whatever position you want. Do so now.

Now lets add cube to the game. Go to GameObjects -> Create Other -> Cube. This will make and select a cube for you. Set the cubes position to 0,0,0 and look at your camera preview (Your camera should be inside your cube). What do you see? Nothing. This is because you are inside the cube. To solve this Select the second of the four buttons (the one to the left of the rotate command) this will create 3 arrows around your object. They allow you to move the object along it's X,Y and Z axis. Using this and some logic drag the cube into the view of your camera. Now hit play. You should see something like this:


Your cube hardly looks like a cube right? Well we can fix that. Lets add some lights!

First lets add a spotlight from the Camera. A flashlight if you will. Select your Camera and click on the Component Menu and navigate to Rendering and select Light. This will create a sphere of light emitted from the Camera. But we don't want that! You will notice that a new menu was added in the Object Inspector (the Right Menu). The new menu should be called "Light" and you should notice that an abundance of menu's is available. All you have to do is select the "type" option and click Spot. This will change the light from a sphere of light to a cone of light. Much better for a flashlight. Note: If you selected directional this will apply light across the entire Scene. You probably don't want that.

Now your cube should have some life! To make this look better make sure your cube is farther away from the camera than the above screen shot and that you can see at least three sides. Unfortunately the free version of Unity does not allow you to use Shadows. This means that you are going to have a rather unrealistic amount of light in your scenes. If this bugs you try a different engine or make use of Projectors and Blob Shadows (Not covered here). Or you could find some money and buy Unity...

That's all for now. I'm trying to install new drivers and they are screwing with my display. I can't even open Unity anymore. If you are having trouble or something doesn't make sense then make sure you comment below with your questions.

Next time we will write a script and import our ship!

Also, I hid the Wallpaper Wednesday Secret Link in here somewhere. Can you find it?
Their is 15 of them!