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

Unity3D: From 0 to 3D Hero

Introduction to game creation in Unity 3D using C#
by

Adrian Ciura

on 27 October 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Unity3D: From 0 to 3D Hero

from
0
3D
Hero
http://unity3d.com/
"Taking the pain out of game development"
Unity 3D is a game creation system.
Consists of:
Game engine written in C/C++
IDE for game development
Mono for running game scripts
Unity Web Player (web browser plugin)
Windows
OS X / Mac
Linux (Ubuntu)
Mobile:
iOS (free / Pro $1500)
Android (free / Pro $1500)
Flash Player (buggy use Unity Web Player)
Windows 8 Store - available in Unity v4.2
BlackBerry 10 Open Beta http://unity3d.com/beta/blackberry10
Negotiable:
PlayStation3
Xbox 360
Wii / Wii U
Supported platforms
About Unity 3D
Integrated Unity Asset Store
Good and easy to find help, manuals, community, forums, wiki, etc
Won many awards for mobile game developer technology
Powerful, uses DirectX 11
Possibility of creating custom shaders
Games and Companies using Unity 3D
Bad Piggies, Rovio - iOS, Android, PC, Mac
Guns of Icarus Online, Muse Games, PC
MechWarrior Tactics, Roadhouse Interactive, Web

Unity GDC '13 Showreel
List of games: http://unity3d.com/gallery/made-with-unity/game-list
by Adrian Ciura
Scripting
Available scripting languages: C#, JavaScript/UnityScript, Boo
Scripting in C#
Edit scripts in your favourite IDE for C#
Good integration with Visual Studio
Debuging using MonoDevelop
Unity 3D uses Mono version compatible with .NET 3.5
Unity IDE
Console / Error log
Hierarchy
Project
Scene / Game preview
Inspector
Scripts must derive from MonoBehaviour class
Scripting in C#
Awake() - run when scene is loaded. Use instead of a constructor for init
Start() - run before the first call to Update. All Awake() functions are run before any Start()
Update() - This function is called before rendering a frame. This is where most game behaviour code goes, except physics code.
LateUpdate() - Called after all Update functions have been called.
FixedUpdate() - This function is called once every physics time step. This is the place to do physics-based game behaviour.
OnCollisionEnter(collision) - handling collisions
Scripting in C#
Prefabs
Dynamic creation of game objects
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.AddComponent<Rigidbody>();
cube.transform.position = new Vector3(x, y, z);
var object = Instantiate(prefabName, new Vector3(x, y, z), Quaternion.identity);
Destroy(object);
GameObject -> UnityEngine.Object
AudioSource audio
Camera camera
Collider collider
Transform transform
GetComponent<T>() where T:Component
SendMessage(methodName, object value) - calls the method on every MonoBehaviour in this game object.
void BroadcastMessage(string methodName, object parameter) - call method in any other script attached to this gameObject and all is children
Component -> UnityEngine.Object
Base class for everything that can be attached to GameObjects.
Base class for all entities in the game.
Scripting Tips & Tricks
Public properties are not shown in the Unity Inspector, only public fields.
Avoid using the constructor or variable initializers, use Awake().
All scripts are compiled to .NET dlls, so you can use any .NET language to write your game scripts.
Mono Compatibility http://docs.unity3d.com/Documentation/ScriptReference/MonoCompatibility.html
Debug.Log(message);
Debug.DrawRay(point, normal, color);
Debugging
Unity 3D space
Layout of X, Y, Z planes
y
z
x
(0,0,0)
Rotation
UnityEngine.Object
Component
Behaviour
MonoBehaviour
Runtime class hierarchy http://docs.unity3d.com/Documentation/ScriptReference/20_class_hierarchy.html
Transform
Rigidbody
Collider
Camera
Animation
AudioSource
All custom scripts
AudioClip
Mesh
Material
Texture
(...)
GameObject
contains Components
Immediate mode GUI
Creating 2D GUI
void OnGUI() {
if(GUI.Button(new Rect(0, 0, 100, 50), "Play Game"))
{ //returns true only once when clicked
// handle button click here
}
}
(0,0)
(Screen.MaxWidth,
Screen.MaxHeight)
http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html
GUI.Toolbar - list of buttons
GUI.Window() - container of controls,
can be dragged-n-dropped
GUI.RepeatButton() - executes each frame update, when pressed
GUI.Box
GUI.TextField - editable text field
GUI.HorizontalSlider / GUI.VerticalSlider / Scrollbars
Creating 2D GUI
GUIStyle and GUISkin
You can change the appearance of your GUI using styling similar to CSS.
Creating 2D GUI
Automatic layout
void OnGUI () {
GUILayout.BeginArea(new Rect(50,50,100,100));
GUILayout.BeginHorizontal();
GUILayout.Label("This is an important button");
GUILayout.Button("Click me");
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
User Input
Mouse
Keyboard
Mouse plane (0,0) is in Left Bottom, (maxWidth,maxHeight) is in Top Right.
Input.GetMouseButtonDown(0); 0=left, 1=right
Input.mousePosition
Left-Hand coordinate system
RigidBody - Physic simulation engine
Controls game object's position through physics simulation.
Collider component
CharacterController : Collider
drag = air resistance (0=rock, 10=feather)
Collider component is required for collisions to occur.
Kinematic = object that has transform changed in scripts, but also physics is applied.
Angular drag = air resistance for rotation
MonoBehaviour -> Behaviour -> Component -> Object
Touch
Based on iOS API
Input.touches -> array of Touch structs
Movement
float value = Input.GetAxis("Horizontal" / "Vertical")
value is between [-1,1], with 0 as neutral position.
http://docs.unity3d.com/Documentation/Manual/Input.html
my example project
Input.GetButton(btmName) / GetButtonDown() / GetButtonUp() - returns true while pressed, e.g. if(Input.GetButton("Fire1")) { ... }
Input.GetKey(key) / GetKeyDown(key) / GetKeyUp(key)
Possible collider types:
Box
Sphere
Capsule
Mesh
How to attach a debugger to a script:
http://docs.unity3d.com/Documentation/Manual/Debugger.html
Using compiled Mono DLLs in Unity
Just drag the dll to the Unity project like any other asset.
How to compile the DLL that uses UnityEngine.dll
http://docs.unity3d.com/Documentation/Manual/UsingDLL.html
Your custom class can use Unity's classes, they are defined in:
UnityEngine.dll
UnityEditor.dll

On Windows they should be stored in:
C:\Program Files\Unity\Editor\Data\Managed
Importing assets
Texture - an image file. Can be printed on a mesh or on GUI.
A mesh consists of triangles arranged in 3D space to create the impression of a solid object.
3D / Polygonal Meshes
Texture
How to make a 3D model
Hard way - Make it Yourself
Find an artistic friend
Buy one in the Asset Store or on the Internet
Blender (also Google SketchUp)
3D Studio Max
Maya and many more
Use her/him to create a model ;)
Create one dynamically in code
Use Mesh class and good luck ;)
http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html
Sound effects / Music
Vertices (Verts)
Edges
Polygons (Polys)
Mesh
Camera
Lights
Point light
Area light
Direct ligt
Ambient light
Spotlight
Shadows
Hard
Soft
None
Captures and displays the world to the player.

Game can have many camera objects.
AudioListener - only one on the scene, usually attached to the camera
Audio Source - plays Audio Clip, add it as a component to gameObjects producing sounds.

Unity can import folloing audio files:
.aif, .wav, .mp3, and .ogg.

Supported tracker modules:
.xm, .mod, .it, and .s3m
Creating Retro audio files:
SFXR https://code.google.com/p/sfxr/
web app: http://www.bfxr.net/
Particle Systems (Shuriken)
http://docs.unity3d.com/Documentation/Manual/ParticleSystems.html
Particle Systems in Unity are used to make clouds of smoke, steam, fire and other atmospheric effects
Animations - Mecanim Animation System
Support for Multiplayer Games
- Networking
It's possible to use .NET framework for communication e.g. .NET Remoting, WCF (from .NET 3.5), etc.
Probably also SignalR (.NET 3.5 client).
Navigation - NavMesh and Pathfinding (Unity Pro Only)
Navigation mesh used by game agents to navigate the world.
Pathfinding - finding a path to get to a destination.
http://docs.unity3d.com/Documentation/Manual/NetworkedMultiplayer.html
Shaders
http://docs.unity3d.com/Documentation/Manual/NavmeshandPathfinding.html
80 build-in shaders
Custom shaders:
Surface shaders - Cg/HLSL
Vertex and Fragment shaders - Cg/HLSL
Fixed function shaders - ShaderLab (CgFX)
List of build-in shaders:
http://docs.unity3d.com/Documentation/Components/Built-inShaderGuide.html
References
Unity manual
http://docs.unity3d.com/Documentation/Manual/index.html
iOS Authoring requires an Intel-based Mac running Mac OS X "Snow Leopard" 10.6 or later.
In order to build to an iOS device, you must be an authorized (standard) iOS developer.
iOS Game Deployment
Building for IPhone creates a complete Xcode project.
http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

http://www.richardlord.net/blog/why-use-an-entity-framework

https://github.com/DavidArno/Ash.NET

http://www.tomseysdavies.com/2011/01/23/entity-systems/

Component pattern: http://gameprogrammingpatterns.com/component.html
Allow a single class to bridge multiple domains without coupling the domains to each other.
Entity System Framework for Games
Data-Oriented Programming
QUESTIONS?
???
???
Unite Nordic 2013
http://unity3d.com/unite/nordic
`
Malmö, May 21-22, 2013
Easy to learn and use
Multi-platform publishing
Huge community (1.3m registered developers)
Strong points
Tutorials on how to create 3D models:
http://forum.unity3d.com/threads/54064-How-to-Make-a-3D-Model
DEMO
Using Unity3D IDE to create a game world
The rotation of the transform in world space is stored as a Quaternion.
Books
Game Development with Unity, Michelle Menard, Course Technology PTR, 476 pages, January 2011
Beginning 3D Game Development with Unity: The World's Most Widely Used Multi-platform Game Engine, Sue Blackman, Apress, 992 pages, May 2011
Unity 3D Game Development by Example, Ryan Henson Creighton, Packt Publishing, 384 pages, September 2010,
y
z
x
(0,0,0)
All rotations are done clockwise.
Allows for easy user control over the game object.
Game object has collisions.
http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.html

//How to rotate and move a gameObject with CharacterController componentpublic float speed = 3.0F;
public float rotateSpeed = 3.0F;

void Update() {
CharacterController controller = GetComponent<CharacterController>();

transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);

Vector3 forward = transform.TransformDirection(Vector3.forward);
float curSpeed = speed * Input.GetAxis("Vertical");

controller.SimpleMove(forward * curSpeed);
}
http://www.kongregate.com/unity-games
More Unity games to see:
More Unity3D resources:
* Unity Gems - Scripting, AI, Shaders, Finite State Machines, Advanced topics
http://unitygems.com/
* Creating an RTS in Unity3D
http://stormtek.wordpress.com/2013/01/01/creating-an-rts-in-unity-part-i/
* Serious Games: An AI Approach
http://seriousgames-zheroth.blogspot.com/
Full transcript