Dana Vrajitoru
B583 Game Programming and Design
Introduction to Unity
Unity
- A game engine that combines visual scene editing with scripting.
- Proprietary application, license by Unity Technology. Free version
available for individuals or small companies.
- Provides deliverables for a great variety of platforms, including
online and mobile.
- Currently dominates the game development market, and is extending
into other production areas.
- Provides a variety of useful tools and a comprehensive library.
Features of Unity
- Scripting can be done in C# or JavaScript.
- Choice between 2D and 3D games.
- Integrated physics engine.
- Integrated collision detection. A variety of (editable) colliders
that can be attached to game objects and trigger functions.
- Other useful tools: skyboxes, particle systems, light sources.
- Provides a set of game templates that we can start from.
Project
- Applications start out as projects.
- A project is composed of one or more scenes.
- A playable executable results from one or more scenes.
- A scene contains a display area, with a camera defining its size
and properties, and several game objects.
- The Hierarchy contains a list of all the game objects in a scene
together with their dependencies.
- The Inspector displays all the attributes and components of the
selected game object.
- Resources are organized in Assets.
Special Classes
- All the objects created in a scene belong to classes derived from
GameObject.
- All the scripts attached to game objects defining their
functionality are derived from MonoBehavior.
- The object that a script is attached to is identified by
gameObject.
- The script component itself is referenced by "this".
- The script has access to components of the game object through
calls to GetComponent<name>()
Callback Functions
- The class MonoBehavior defines several callback functions
that can be overloaded by derived classes to attach behavior to
specific events.
- Start - called once when the program is loaded.
- Update - called once every frame of the game. Allows
interaction with the Input class.
- OnGUI - allows interaction with key/mouse events through
the Event class.
- OnMouseOver, OnMouseExit, etc. - more specific
events. Some of them require a collider.
- OnTrigger - callback for collision detection.
More on Objects
- Finding a game object with a given name:
- Game Object objRef;
- objRef = GameObject.Find("objName");
- Some attributes/ components can be accessed directly
- rigidBody2D.AddForce(...);
- GetComponent<RigidBody2D>().AddForce(...);
Tutorials