Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Unity 3D

A project that explains how Unity 3D works
by

Scott Hickmann

on 24 September 2015

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Unity 3D

About
- Unity is primarily a SDK (software development kit) or in an easier name for it an application for video games. Used to develop two dimensional or three dimensional video games but can also be used to make other games such as simulations. It can be used for educational games or learning to code.

- Unity is unique from other video game SDK's offered in the market in that unity is optimized for the widest range of platforms that no other game SDK offer.


How to Install Unity
Go to the official Unity 3D website listed above
Click the button below to get Unity
- Once the button is clicked, choose the edition of unity you want to download; then click the download button. Wait for the download to complete which should take about 15 minutes depending on your broadband connection.

- Once the download is complete, follow the installation wizard instructions.

- Once finished, you are able to use Unity 3D; however, how do you actually use Unity?
User Interface
Before exploring how the workflow of Unity works, one must explore the user interface; therefore, here are the major windows that the user will use to program his game
Project Browser
- This window here contains all the assets (sound, scripts, graphics) that will be used in your game and shows the folder structure of all the assets in the game, and which folder is each asset in

- There is also a search bar at the top of this window to find specific game objects or folders in the project window

Hierarchy
- This window here shows all the game objects and prefabs (discussed later) that will be shown in the game

- The user can make some game objects into children of another game object by simply grabbing the child game object into the desired "parent" game object
Tool Bar
- The tool bar allows the user to change certain parts of the program

- At the right here shows the buttons that stop, play, or pause a test version of the game in the game view
Tool Bar (Cont.)
- The buttons under this text are used to manipulate the current view in scene view
- The buttons to the left affect the scene view display
- The layers tab affects what game objects are currently displayed
- Layout tab affects the arrangement of all views/windows
Scene View
- The scene view gives the user a glimpse at what the game will look like, and allows the user to change physical properties of each game object and the entire game itself
- As stated earlier, the buttons to the far left of the tool bar are used to manipulate the position, rotation, and scale of the game object
- The button above the scene view screen affects the game such as perspective (2D or 2D) and sound
Inspector
- The inspector view/window allows the user to see the components that feature the properties of a certain seleted game object.

- The user can change many properties of these components, such as the reference file for a component, values, colours, graidents, arrays, and curves, and even change values of scripts (a component as well) during runtime

- Note: you can change the entire layout of Unity3D to suit your style by dragging tabs of the views into areas with pre-existing tabs

- Now that you understand what each view does, lets explore the major component that makes up games: graphics
Graphics
Lights
- Lights define the scene's colours and overall mood
- Lights are also game objects that share components of other game objects, and there are light components
- There are two types of lighting: dynamic which calculated illumination and shadows of 3D meshes in real time, and baked which is lighting precalulated on a mesh and saved as a texture
- There are four types of lights used in dynamic lighting and the production of baked lighting:
-point lights: shine light from a single point to all directions
-spot light: shine in one direction
-directional lights: create the lighting effect similar to the sun/moon,
-area light: casts light from a plane of a polygon, but can only be used for light baking as this light is extremely graphic intensive
-There are also many effects that can be applied to these light sources:
-Cookie: texture that allows the light to emit patterned shadows. The cookie must be 2D textures for spot and directional lights, but a 3D texture, such as a cube, for point lights
-Shadows: determines the sharpness and darkeness of the shadow and the distance from the object to when the shadow starts
-Halo: creates a sphere of light depending on the range of light
-Flares: similar to a halo, but imitates a bright source of light seen through optical glass





Cameras
- Cameras give the perspective of a game
- Cameras should always be made a child of the player game object as the camera will always move with the player game object when it is moving
- Cameras can display objects in different perspectives based on its projection mode. Perspective mode displays objects with diminishing perspective whereas orthographic displays objects in two dimensions without diminishing perspective
- All cameras render scenes with empty space which can be considered as a background. The camera's clear flags property defines what is displayed in this background by its four settings:
- Skybox: sets background to a sky box, a material composed of many images surrounding the scene
- Solid Colour: sets background to a user specified colour
- Depth Only: sets background of a current camera to the rendered scene of another camera with a lower depth value
- Don't Clear: prevents camera from redrawing the scene
- Cameras also have a culling mask property that limits the camera to what objects it can render based on the layer the culling mask has selected
- Now that the major graphic features have been covered, lets move onto animation and how to make these graphics move
2D Graphics
- 2D graphics in games are commonly known as sprites

- When importing new sprites for the game object, the texture type of the image must be set to sprite

- In addition, there is a sprite mode for that sprite. If the sprite is a single image, set spite mode to single. Else, if the spite has various images, set sprite mode to multiple

- Sprites with multiple images can separate these images through the sprite editor. Once the images are separated by grid, for animation, or by slicing, for sprite atlas, the images will be made children to the original sprite sheet/atlas

- Sprites use the sprite renderer component to be actually displayed in the game

- Sprites can also be assigned materials, allowing sprites to be affected by 3D lighting, but is unnecessary and slows performance

- Sorting layers in the sprite renderer component allows the user to determine which sprites in the game is rendered first and last i.e. which sprites overlap other sprites
3D Graphics
- 3D graphics, unlike 2D graphics, require two components: a mesh and texture

- In Unity, all 3D graphics of any game object require the mesh filter and mesh renderer components

-The mesh filter determines the mesh, 3D model, of the game object. The mesh filter does not accept skinned meshes as they are used in the animation component of Unity

-The mesh renderer renders the model in the scene, and gives it a user specified material

-The material consists of a texture that is a bitmap image being applied to the mesh, defining colour and depth, and a shader which defines how the mesh reflects light

Before going into the world of graphics, we need to understand the relationship between game objects and components, and creating copies of game objects through prefabs
Game Objects
Game Objects and Components
- All scenes have game objects that represent graphical objects in Unity games

- Game objects contain components that define the properties and characteristics of a game object such as a rigid body which gives mass to an object. Scripts are also considered components as well

- Game objects can be removed from the scene by making them inactive by unchecking the very top left corner of the inspector for selected game objects

- To better identify game objects from one another, tags can be assigned to each game object

- Static, non moving, game objects can be combined into one single large object known as a batch for better game performance
Prefabs
- Prefabs are templates of a game object that can be used to make copies of that game object, and changes made to a copy, or instance, of prefab can be applied to all other instances of the prefab

- To make a prefab of a game object, right click on that object and click Asset then Create Prefab. It is a best practice to create and put all prefabs in a designated prefab folder in the project view

- One can edit instances of a prefab by using the three buttons only available to prefabs: Select which allows the user to select and change settings of a selected instance, Apply which applies these changes to all instances, and Revert which redoes all the changes made to all instances
Particle System
- Particle systems are a special type of 3D graphics which consists of an animation of a large number of 2D images or 3D meshes rendered in 3D space used to simulate fluid entities such as fire and is a component of a game object

- Unity allows the user to create their own particle effects with various of properties to edit in each of the following modules:
- Emission: determines the rate and time interval of each emission of particles
- Shape: determines the shape of each particle
- Velocity over time: determines the speed of all particles at a specified time interval
- Limit Velocity Over Lifetime: determines the constant deceleration of the particles
- Force Over Lifetime: determines the forces, such as wind, that can affect these particles
- Colour Over Lifetime / Colour By Speed: determines the change in colour when particles for the whole animation or when they reach a certain speed
- Size Over Lifetime / Size By Speed: determines change in size of particles during the whole animation or based on their speed
- Rotation Over Lifetime / Rotation By Speed: determines change in rotation of particles during the whole animation or based on their speed
- External Forces: determines the effect of wind on the particle system
- Collision: determines the collisions between particles and solid objects during runtime
- Sub Emitters: determines any particle system creates from a particle when the particle reaches a certain position
- Texture Sheet Animation: sets the animation of each particle
- Renderer: Only for meshes, determines how the mesh is affects in the particle system
Animation
Animator Component and Controller
- In order for animation to be actually played by a game object, the game object needs the animator component
- The animator component holds the animator controller for the game object, the avatar, the rig of the game object, and determines if the animations affect the game objects position, and runs with the physics engine or what is already rendered of the game object
- The animator controller is a state machine, or a visual switch, that determines which animation is played based on parameters whose values are retrieved by scripts
- The animator controller is created by right clicking the project view, th animator controller which is accessed by the animator view below
On the bottom here lists the parameters, which can be bools, ints, floats, or triggers used to transition between one animation to the other when the parameter retrieves a value from a script that is greater than, or matches, the parameters maximum or value
The user is able to create more animation states in three ways:
- simply dragging an animation clip from the project view into the animator view
- right clicking empty space in the animator view and selecting between an empty state, animation clip, or blend tree (discussed later)
- create an animation in the animation window (discussed later). Unity will automatically create it in the base layer of the animator controller
The orange state here is the animation that first plays when the game loads
the arrows between the two states represent the transition between the two states i.e. when one animation starts and the latter ends based on a parameter value
Blend Trees
- Blend trees allows the user to combine and blend two or more animations seamlessly
- To access the blend tree, double click the state with the blend tree
- There are two types of blend trees: 1D trees and 2D trees
- 1D trees use one parameter that controls how each of its motion should be played. The image below shows the contents of a one directional blend tree
This here are the motion fields that represent an animation clip. There are three settings: the Threshold (Thesl) represents the value of the parameter that plays only this animation of the blend, the motion determines the animation clip, and the the time scale (the clock) affects how fast the animation is played
This graph here shows the influence based on their threshold value of each animation, with the red bar showing the current value of the parameter, and the numbers on the bottom represent the threshold of the parameter
- 2D blend trees use two parameters to control how each motion is played
- There are three types: simple directional, where each animation is played for each direction; freeform directional, where each animation is played for each direction, and multiple animations can be played in one direction; and freeform cartesian, where animations are played based on parameter values that do not determine direction. The image below shows the content of a 2D blend tree
With the added dimension, the diagram in the right is very similar to the graph of the 1D graph, but with two threshold values and the red dot representing the current value of both parameters
The motion field setting are still the same from the 1D motion tree, but with two threshold values instead of one
In 1D blend trees, the order of the motion field is important, and should placed from motions with lowest threshold to motions with highest threshold
Unlike 1D tree blends, the order of motion fields does not matter in 2D blender trees
Animation Properties
- Whenever a model is imported, the user can see and change the settings for the animations of that mode when the user clicks the Animations tab in the inspector when a model is selected
- The user is able to see the imported animations that could have come with the model, the length of each animation in frames, the looping of a selected animation, when it starts and ends, the rotation and direction (left, right, forward, backward, up, and down) of the animation, and the flipping (reflection) of the animation
- The user is also able to edit the curves under Curves drop down in the animations tab and define values for an animation such as a jump
- The user is also able to add events under the Events drop down in the animations tab that allows scripts to call functions of an event that occurs at a specific key frame in an animation. The function in that event can only have one parameter
The user can set layers on the animator view to allow several animations to be played simultaneously, or by their weight
Animation Mask
- Sometimes in animation, the user may want to play two animations simultaneously from one character
- To do this, the user can set up a avatar mask
- To set up one, right click on the project view and click Create, then Avatar Mask
- Once created, there are two option for the mask:
-Humanoid: in the inspector, the user can click on areas of the humanoid diagram to select (shown in green) or deselect (shown in red) parts of the humanoid that will be used in the animation for a humanoid model
-Transform: if the model is not a humanoid, then the user can select the skeletal rig of the model and check and uncheck which bones (moving parts) of the model will move during the animation
- The mask can then be applied to their corresponding animation layers in the animator window
Animation View
- Unlike the animator view, the animation view allows the user to make custom animations aside from making them other 3D animation software
- Let's explore the animation view below

At the bottom here lies the tools for the animation view. They are, from left to right (excluding the textbox), the the following
- Record: records the animation
- Play: plays the animation in the scene view
- Backwards and Forwards: moves from frame to frame
- New Keyframe: adds new keyframes for animation
- New Event: adds new events in the animation
The diamonds represent the keyframes of the animation at a specific time, and the rectangles represents the events that happen in the animation at the specific time. The red bar represents the current time at the animation in the timeline
When the animator view is set to curves mode, the rate of change in the game objects or game object's bone transform, rotation, scale can be adjusted and fine tuned by adjusting the tangent of the key frame (diamond) on the curve of the change in game object's position, rotation, or scale
Scripting (Programming)
Programs in Unity are often called scripts that give game objects behaviour; therefore, they are components to the game object
Basics
- To start, lets examine the basics that exists in all programming and programming languages
- All programs use variables that hold a value depending on the variable type. Value variables hold values, but reference variables hold the memory address where all values of that reference is stored
- There are functions in all programs that perform a specific task with a variable or variables that acts as a parameter and two types exist:
- Void: Functions that simply executes algorithms with the parameter(s)
- Variable (e.g. ints, bools, triggers): Functions that return a variable value after executing its algorithms with the parameter(s)
- All function statements are structured like the following (type nameOfFunction (variabletype, variabletype,...)) where variable type is the parameter or parameters depending on user preferences
- All programming languages follow these syntax rules:
- after every statement of code, a semi colon must be placed at the end
- when using the function of a class, dot notation must be used in this manner: class.function()
- anything in the curly braces must be indented for easy to read to code
- comments must be present in all programs for others to actually understand the code. A double forward slash is used for single line comments. For comments with multiple of lines, a forward slash followed by an asterisk marks the beginning of the comments, and an asterisk followed by a forward slash marks the end of the comment. Either symbols must be places before the comment

Basics (Cont.)
- In Unity, there are two similar, but different, programming languages the user can use: C# and JavaScript
- The notable differences between the two are the following
- C# has a default scope of private; JaveScript has a default scope of public
- C# declares variables in the following manner: variabletype variable name = variablevalue; Java declares variables in the following manner: var variablename : variabletype = variablevalue;
- C# declares functions in this manner: returntype functionname (variabletype variablename). Java declares functions in this manner: function functionname (variablename : variabletype) : returntype
- C# has class declarations shown whereas Java does not
- Regardless of programming language, variable can have different scopes which define what functions and classes can access that variable
- variables declared in between curly braces are accessible to any functions and other curly braces within those curly braces
- declaring a variable as private makes the variable accessible only to functions and code blocks within the class the variable was declared in
- declaring a variable as public makes the variable accessible to the entire script and other classes
- Note: all further examples of code are C# examples
Decision Statements
- There are various statements in code that can be used for developing a game objects behaviour
- If, else if, and else statements are used for decision making based on a condition; If's are used to execute an action or process when a condition is met, else if's are used to execute another action or process if the first condition is not met and this condition is met, and can only be used if there is an if statement. Else are used to execute a process or action when no condition is met and can only be used if there is an if statement. The statement is generally an if, else if, or else followed by a conditional statement in brackets and then a code block (curly braces) underneath for executing the code when the condition is met
- An alternative to the if-else statements is using a ternary operator which work the same way as if-else statements, but used for simplifying code and giving a variable a value directly. The structure is generally a variable, followed by an equals sign, then a conditional statement, then a question mark, then a value if the condition is met, then a colon, and finally a value if the condition is not met.
- Another alternative is the switch statement when comparing a single variable to various conditions. The switch statement starts with the word switch then the variable in brackets. Underneath the switch statement follows case statements followed by a value that the variable can reach, and then a colon. Underneath each case statement is the lines of code used to execute and action or process and, at the end of the lines of code, is the line break to get out of the switch statement. Finally, there is a default statement at the bottom of the switch structure with the word default followed by a colon that executes code underneath it should the variables value not match any of the case statements

Loop Statements
- Loops are used for executing the same number of code over and over again, and is generally used for objects that have a number of instances created of them; There are four types:
- While and do-while loops execute the same line(s) of code until a condition is met
- For loops execute the same line of code while increasing decreasing a numerical variable until it reaches a certain number
- For each loop executes the same line of code for every item in an array, and stops when all arrays have been examined
- Many loop statements often incorporate arrays, which are a collection of many different values of the same variable type
- Array statements are composed of a variable type, an opening and closing square bracket ([ ]), an equals sign, the word "new" next to square brackets with a numerical value in it indicating the number of variable elements, or several values separated by commas surrounded by curly brackets
- Similar to an array is an enumeration which is an ordered list of related values.
Functions
- Functions are the major components in scripts

- Users can create their own functions and fine tune them, but there are several other functions that Unity has made already in its various classes

- To begin, all scripts must have the following functions in the order below, from top to bottom:
- Awake(): initializes all variables for the script
- Start(): executes code when the script is first enabled
- Update(): called for every frame and used for non-physics movement of objects, timers, and receiving input, but is not called at a constant rate due to performance of the game affecting overall framerate
- FixedUpdate(): called at a constant rate and is commonly used for adjusting rigid body physics

Functions (Cont.)
- There are several functions used for user input and game object output
- Here are some of the functions for the Input class
- GetKey/GetKeyDown/GetKeyUp(KeyCode): this function determines if a specific key (based on key code) is held, pressed, or released respectively and returns a bool
- GetButton/GetButtonDown/GetButtonUp(String): this function is the same as the GetKey functions, but uses the specific key's string name rather than its code
- GetAxis(String): this function gets the value from a joystick and returns values ranging from -1 to 1. The string parameter indicated the axis the function will return the values from
- There is also the OnMouseDown() method which is a void that executes and action or process once the mouse clicks on the game object
- Once can completely destroy game objects or components from a scene by using the following function: Destroy (GameObject or Component




Functions (Cont.)
- There are functions used for determining moving or rotating an object. They are the following:
- Vector3.Dot(Vector3 from, Vector3 to): determines the dot product of two vector points. Useful to determine whether two vectors are perpendicular to one another
- Vector3.Cross(Vector3 from, Vector3 to): determines the perpendicular axis of two vectors. Used to determine the axis of rotation
- transform.Translate(Vector3): determines how much the game object moves based on the direction of the Vector3
- transform.Rotate(Vector3, float angle): determines how much the game object rotates, in degrees, determined by the float value with the rotational axis being the Vector3
-
- transform.LookAt(transform): determines the forward direction of an object based on the position (transform) of another game object
- Vector3.Lerp(Vector3 from, Vector3 to, float time): determines vector values between two vectors that allow the game object to move smoothly from one vector to another
- To retrieve the components of the game object or other game object, use the following method to get the settings of that component: GetComponent<componenttype>()
- The user can also disable game objects in the game using the following function: GameObject.SetActive(bool)
- The user can also create clones (Prefabs) from script rather than dragging the prefab onto the scene view by using the following functions: Instantiate(GameObject) or Instantiate (GameObject, Vector3 position, Vector3 rotation)
- Functions can also be called at specific times using the following functions: Invoke (Function name, float time) to call a method once in float time, InvokeRepeating (Function name, float time, float repeating time) to call a method repeatedly in repeating time interval, and CancelInvoke() to cancel the invoke
Physics Scripting
- There are many functions in scripts that deal with the physics of game objects
- The following are 3D physics functions:
- rigidbody.AddForce(Vector3 direction + magnitude, ForceMode): applies a directional force to that game object based on the force mode which can be for objects with mass (Force and Impulse) and objects without mass (Acceleration and Velocity Change)
- rigidbody.AddTorque(Vector3 axis + magnitude, ForceMode): applies a rotational force to that game object based on the force mode which was defined in the previous dash
- Physics.Raycast(Vector3 origin, Vector3 direction, Raycasting hitinfo, float distance, int layer mask): used to determine if an object with a collider hits a ray emitted by another game object if that object is less than the float distance and in the layer specified by the user
- OnCollisionEnter (Collision): executes an action or process in this function whenever one object with a collider collides with another object with a collider

Classes
- Classes contain all the functions and variables (called fields) that is used in the class which can be accesssed by other classes if made public
- They contain constructors that initialize values for private fields of the class. Constructors can also contain parameters that will be used for initialization
- Classes contain properties which are global variables used to set private variable values within the class, and return the value to the class that called the property
- Classes also feature static variables, methods, and classes. Static variables are variables that, when changed in one part of code, is changed for all parts of code using that variable. Static methods are methods that do not need an instance of a class to be used, and static classes are classes that can be accessed without creating an instance of it
- Functions can be overloaded, meaning that a class can have many functions with the same name, but different number of parameters and parameter values, or become generic where they can accept any type of variable value. Generic functions are structured like this (public type nameOfFunction<variabletype>(variabletype param)) and accessed by other classes like this (type.nameOfFunction<variabletype>(variabletype))
- Classes can also have subclasses which can access variables of the parent class if not private. The class declaraction of a subclass is as follows (public class childClass : parentClass). When creating an instance of the subclass, the parent class can be used as the type since the subclass is part of the parent class; this is known as downcasting

Classes (Cont.)
- Classes can also use interfaces where classes implements functions to these interfaces that will be used by other classes. The interface statement is as follows (public interface nameOfInteface)
- There are also extension functions in Unity where, in the brackets of the method, uses the word this beside the variable type and name. Note: extension methods often use reference variables. This allows functions to be called without putting in any arguments (variables in function brackets)
- Classes can also be assigned to namespaces which contain other classes to prevent conflict and confusion between scripts. The statement of a namespace is follows (namespace nameOfNamespace)
- In addition to functions designed by the user, there are coroutines, special functions executed at intervals. The statement structure of coroutines are the same as ordinary functions but with an interface name at the left side of the entire function statemenet, and use special yield statements at the end of code blocks that determine the time interval for each time the function is executed
- There are also delegates in classes which acts as containers for functions. Delegate statements are structured just like ordinary functions, but with the word delegate at the left side of it. To use a delegate, an instance of the delegate must be created, and, from there, the user can assign functions of the same type as the function by simply stating that the instance of the delegate equals a function, and, in the next line, write the delegate as if it were a function with the appropriate parameter of the stored function. Delegates can store multiple of functions, and execute them all at once when called like a function
-
Physics for Graphics
- Unity possess a somewhat powerful physics engine, allowing game objects to act in real life physics conditions

- Much of the physics in Unity is controlled by Rigid Body, which give the object mass, Collidier, for collision detection, and Joint, for the swinging action of some objects, components

- There are also physics textures that have specific static and kinetic coefficients to replicate an object being stationary in a slope or an object hard to push
Sound
- Unity would not be a game engine without sound capabilities

- There are two types of components that control sound; the audio listener and audio source

- The audio listener is used to record sound and responsible for playing sound for the game. The component is already established in the camera

- the audio source contains all the audio files, MP3 to WAV, for them to be played in code, and can be changed to having very high or low sounds or octaves for example
Tool Bar (Cont.)
By: Pablo Maquaire, Logan Cariou, Scott Hickmann, Maxime de Belloy
Unity 3D
Here is the inspetor window
Game View
- The game view/window shows a representation of the final game.
- The user can see stats of the game in the stats button above, and see the various components used in the game in the Gizmos button above.
You can switch between scene view and game view by clicking those buttons.
Full transcript