CS248 Lecture 2: Introduction To Unity
CS248 Lecture 2: Introduction To Unity
INTRODUCTION TO UNITY
Create an empty prefab and it will go into your assets folder. A gray prefab is an empty prefab!
Prefabs
Drag and drop the GameObject onto the gray prefab object and the prefab will turn blue! (and so
will the GameObject in the hierarchy). Blue indicates that it is an instance of a prefab and Unity
will warn you if you try to change that object!
Now you can delete the GameObject that exists in the hierarchy, drag and drop the prefab back
into the hierarchy and you will see the GameObject show up again!
Editor Camera Controls
“Maya”-like Controls:
› Alt + Left Click & Move: Rotate Camera
› Alt + Right Click & Move (Or Scroll Up/Down): Move camera back and forth
› Alt + Middle Click & Move: Move camera up/down or left right
Flythrough Mode:
› Click and hold right mouse button and now you can use FPS-like controls to move around
through the scene (WASD, Q/E to move up down).
Unity Documentation: http://docs.unity3d.com/Manual/SceneViewNavigation.html
Editor Object Controls
“Maya”-like Controls (after selecting an object):
› W: Activate translation widget.
› E: Activate rotation widget.
› R: Activate scale widget.
Manual Movement:
› Modify position/rotation/scale in the Inspector.
› Rotation is in Euler angles. Rotation order: Z, X, Y.
Unity Documentation: http://docs.unity3d.com/Manual/PositioningGameObjects.html
Creating Geometry via the Unity Editor
Setting Up The Scene Camera
Do not confuse the scene camera with the editor camera.
Unity scenes by default come with a “Main Camera.” Notice the tag of “MainCamera” in the inspector, this will be useful
for accessing the camera from your scripts.
“Camera Preview” box is useful to see what your camera can see.
“Camera Preview” is what you will see when you hit Play!
Setting Up The Scene Camera
Moving the scene camera can be done manually by changing the position/rotation/scale in the Inspector.
Or you can move the editor camera around as mentioned earlier, select the camera and align the camera
to the view. Note that your camera should be selected before doing this.
Hit play and this view will be sufficient for the screenshot in Assignment 1.
Import External Objects
Create and export an object from Maya/Blender/3ds Max as either an *.OBJ or a *.FBX. You can
save this anywhere.
› Why *.FBX? You will see later when we start talking about character animation.
Then import this asset into Unity. Unity will take care of everything for you.
Alternatively, you can just save your *.OBJ or *.FBX inside the “Assets” folder.
› You will need to right click on the folder it is in and click “Refresh” to get it to show up.
Import External Objects
Click and drag the object from the assets library into your scene hierarchy and it should now show
up! There is a difference in how the GameObject is setup depending on whether you use an FBX or
OBJ but that difference is not relevant for now.
Shading and Materials
Fairly easy to write your own shader but the Unity Standard shader is very powerful and can
probably be used in most situations!
In most cases you will want to select a shader that comes with Unity and modify the material
properties to achieve the look that you want
Manual Shader Documentation: http://docs.unity3d.com/Manual/ShadersOverview.html
Standard Shader Documentation: http://docs.unity3d.com/Manual/shader-StandardShader.html
Materials Documentation: http://docs.unity3d.com/Manual/Materials.html
Importing Textures
Process is the same as importing an external object. This time, instead of selecting an *.FBX or *.OBJ, select a *.PNG,
*.JPG, etc. You can also place the images inside the Assets folder manually.
Note that you should make sure your imported object has a UV map before continuing! You can check this in
Maya/Blender/3ds Max.
Using Textures
Click on the object you imported in the scene hierarchy and expand the shader properties in the Inspector.
The “diffuse” texture that we used in CS148 is now the “Albedo.” There is no distinction between the diffuse and specular
color as you saw with the Epic BRDF.
› Look at CS148 Assignment 4 if you want great (no bias) refresher on what the BRDF/Material does.
› http://web.stanford.edu/class/cs148/assignments/assignment4.pdf
Using Textures (Option 1)
Click and drag the imported texture onto the square next to “Albedo” and your object should now
have a texture on it!
Using Textures (Option 2)
Click on the circle next to Albedo and select your texture in the dialog box!
Lighting
Lighting Documentation: http://docs.unity3d.com/Manual/Lighting.html
Global Illumination Documentation: http://docs.unity3d.com/Manual/GlobalIllumination.html
Lighting is accomplished with the “Light” component.
Creating a Light
Light Component Properties
Light Types:
› Directional Light
› Spot Lights
› Point Lights
› Area Lights
Light Component Properties
Color and Intensity
Unity Tutorial
HOW TO DO
ASSIGNMENT 1
Questions?
YOU CAN ALSO ASK
ME AFTER CLASS.