To get an idea of what to expect in the remaining chapters, we can drop in a few simple shapes into the scene. Select GameObject→Create Other→Cube to drop a cube into the scene viewport. To pan around in the scene, press the Q button. Use the left mouse button in the scene viewport to pan around. The mouse wheel zooms the cube, and the right mouse button enables common “first person shooter style” navigation with WASD keyboard keys and mouse-look mode.
The W key enables the object translation mode. Select any tool aside from the View tool and you’ll be able to box select or directly click on an object in the scene. Shift + Box select adds to your selection.
Press the CTRL key while making a selection and you will unselect the next selected item.
The Transform tool allows you to pick and drag the object around in the scene. Dragging left and right on a property in the Inspector will change the individual value.
You can watch the Position values change under the Transform tab in the Inspector panel as you manipulate the cube. The numbers can also be entered directly into the X, Y, and Z fields of the Inspector panel if you want to have a precise control over an object’s placement.
The E key will turn on the Rotation tool. Like the Transform tool, you can watch the object’s rotation update in the Inspector panel as you manipulate the object in the scene.
The R key activates the Scale tool and you can change the size of an object or enter the values in the Inspector panel. All three of these tools allow you to pick and drag on various parts of the Manipulation tool in the scene. This changes the manipulation’s behavior by constraining the action to one or two axes of freedom.
On the top right of the Scene viewport is a little widget that allows you to switch between various views of your scene. Top, front, and side views can be accessed quickly by clicking on one of the cones on the widget’s cube. To change between a perspective and a parallel camera view, click on the Persp/Iso icon to toggle how the scene is rendered.
2.6.5 Working in a Live Scene
While the game is running, you’re allowed to reach into the game through the Scene panel. You can select and move objects while the code is being updated. You can also use the Inspector panel to manipulate a selected object’s parameters and variables.
Once you stop the game, any changes you made to anything in the scene are immediately reverted to whatever settings they had just before you started the game. This might mean losing some settings which you have tuned while playing the game.
If the settings were saved every time you stopped the scene, then testing a scene would be more troublesome. Going through a level shooting all of the zombies means that the next time you start the level again, everything would already be dead.
2.6.6 Saving a Scene
All the changes we’ve been doing have been created and applied to objects in a scene. After adding objects to a scene such as lights, cameras, and other objects, it is time to save the scene. The standard Save dialog instructs you to save and name the scene. The default location for a scene is the Assets directory in the project. It is possible to create a sub-directory in the Assets directory called Scenes or something similar; however, for our use, we’ll save the scene in the Assets directory of the project.
2.6.7 Opening a Scene
While working with each and every tutorial of this book, there’s always going to be a scene file named Scene. Throughout the book, the tutorials will begin with the Scene file found in the downloaded project. To open the scene simply double click on the scene icon located in the Project panel under the Assets directory. You can also select File→Open Scene to open any scene in the project.
2.6.8 What We’ve Learned
Creating and assigning a new C# file to an object doesn’t require so much work. There are plenty of ways to do this within the Unity 3D Editor. Once we add some code to the new C# file we’re just a button press away from seeing our code in action. With some of the tutorials in this book, you’ll be expected to create a new project, create new scripts, and assign the scripts to an object in a scene. With some of the more detailed tutorials, a completed version of the scene will be provided for you.
Amazingly enough, other professional tools for building things for Windows, Linux, or OSX all involve a similar process for creating desktop software. There’s generally a lot more footwork involved with getting started. Templates, frameworks, and other IDE setup processes are required before even being able to get something to print out to a Console panel.
Learning C# with Unity 3D is one of the shortest routes from typing to execution that I can think of that has the most interactive results. The Editor itself allows you to interact with variables and values in real time. Selecting an object in the Scene editor and changing numbers in the Inspector panel allow you to have a direct connection to your code and see the changes in behavior in real time. This kind of interaction is only possible in the real-time nature of a game engine.
So far, we’ve gotten to do a bit of setup and preparation. Getting Unity 3D up and running is necessary, and if you’ve gotten stuck somewhere, make sure that you check the internet for any solutions. Naming files and classes correctly is also necessary to get your code to work. A single spelling error can break your code and nothing will work. Also remember that the upper- and lowercase letters matter a great deal. Naming your file the same as the contained class is also important, as a mismatch will also break your code and produce errors.
Programming is a highly rewarding endeavor. Don’t let a small hitch bring you down. As you accumulate knowledge, writing code will only get easier. After you’ve learned one programming language, it is much easier to learn another.
I hope that after you’ve managed to wrap your head around C#, you’ll be able to take the knowledge earned here, look at other programming languages, and feel a need to learn more. If you’re an artist, adding the cool tricks that programming can offer to your palette of skills will only make you richer. And I mean richer in more than just the depth of skill.
Leveling Up: The Journey Has Just Begun
Get ready for some new concepts. Telling computers what to do and how to do it takes a lot of work. Computers aren’t very bright; they’re actually downright dumb. They do exactly what you tell them to do. If you get unexpected behaviors, it is up to you to make yourself clearer.
Of course, this all involves talking to a computer in its language, something that we should be able to do part way into this book. Once we’ve gone through the basics, we should be able to tell the computer simple commands and get expected results.
If you feel that you’ve gotten to a saturation point while reading this book, put this book aside for a bit and practice some of the concepts you’ve just learned. If you feel that you’ve explored all you can on your own, it is time to come back and pick up where you left off.
