unity overview using unity 3.5 (free version) [1]: //docs.unity3d.com/documentation/scriptreference

23
Unity Overview Using Unity 3.5 (Free version) [1]: http://docs.unity3d.com/Documentation/ScriptReference / [2]: http:// docs.unity3d.com/Documentation/Components/index.html [3]: http:// wiki.unity3d.com/index.php?title=Head_First_into_Unity_with_Java Script

Upload: victoria-barber

Post on 17-Dec-2015

283 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Unity Overview

Using Unity 3.5 (Free version)

[1]: http://docs.unity3d.com/Documentation/ScriptReference /[2]: http://docs.unity3d.com/Documentation/Components/index.html[3]: http://wiki.unity3d.com/index.php?title=Head_First_into_Unity_with_JavaScript

Page 2: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

What is it?• A Game Engine / IDE

– A level editor– Management of Resources

• Meshes, lights, cameras, particle effects, …

– Plugin (Component) architecture– Script support (JavaScript, C#, Boo)

• Versions: – Free (0$), Pro ($1500)

• Flash (+$1500), iOS (+$1500), Droid (+$1500), Team (+$500)

– [Pro] NavMesh– [Pro] Audio Filtering– [Pro] Advanced pre-made shaders– [Team] SVN-like functionality– [iOS/Droid] Deploy to iOS/Droid devices (OpenGL ES?)

Page 3: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

First step• Create a new project– A new directory tree

• Assets – put your resources here• Library, ProjectSettings, Temp

• A new .unity file– Each one is a "level" (group)

• Placement data for all level objects– Parameters for each

• Global settings

– A binary (unfortunately) file in /Assets/– Can have multiple "level's" at one time

• GUI / Menu "level", Level1-n • (role of build settings)

Page 4: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Unity Player (IDE/Editor) overviewTransformTools Preview/Play

Scene

Inspector

Hierarchy Project (Assets)

Page 5: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Add Resources & Instances• Either

– Save a resource in the Assets folder– Or drag-and-drop into the Project pane

• If you edit the resource, it's automatically updated in Unity– a great feature!

• Some supported resources– .blend (2.5+) : runs the fbx exporter– .fbx (maya, motionbuilder, …)– images– sounds– script files– …

• Drag it onto the scene (or hierarchy) to add to the hierarchy.

Page 6: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Scene Navigation

• [Alt+LDrag]: rotate camera• [Alt+MDrag]: Pan camera• [Alt+RDrag] or [Scroll]: Zoom• [RClick] + WASDQE:

– First-person camera mode– WASD to move– QE to go down/up

• [F]: Center the view around the selected game object• [ArrowKeys]: Move on the XZ plane (ground)• You can also use the buttons in the upper-left (SLOW!)

Page 7: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

GameObjects

• A "thing" in the game– the current Level's ground– the player– enemies– health pickups– trigger point– …

Page 8: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

GameObjects, cont.• [Create an emtpy game object]• Composed of components– Transform (a scene node)• All GameObjects have this.• Scale, Rotation, Translation…• …from parent node• The hierarchy pane is really a scene graph

– Mesh Filter / Mesh Renderer– Physics• Collider (capsule, box, mesh, …)• RigidBody

Page 9: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

GameObjects, cont.– ParticleEmitter– GUITexture / GUIText– AudioSource (2D or 3D, depending on asset)– …– Script (for anything else)

• Tags and Layers– Layers:

• Selective rendering, selective hit-detection• A bitmask (32-bit integer)• e.g. "Ground", "Post-processing"

– Tag:• Useful mainly in scripting• Also a 32-bit integer• A "group" (fast FindWithTag methods)• e.g. "Main Camera", "Player", "Pickup", "Exit"

Page 10: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Prefabs

• A template for a commonly-used game object• Assets=>Create=>Prefab

– Drag an existing object from Hierarchy to new Prefab– Shows up in blue in Hierarchy– Drag more instances of Prefab onto scene– If you change the prefab definition, all instances will change too.

• You can modify the values of component attributes, but not the "structure" (e.g. components, although you can disable them)

• You can "break" the prefab connection by GameObject=>Break Prefab Instance.

Page 11: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Character Controller

• Import under Assets=>Import Package…• Put a 3rd person controller and camera on the

player node– Drag the main camera transform onto the 3rd

person camera's "camera transform" property– Make sure the main camera is tagged with the

"Main Camera" tag.• [Later] A good example of a complicated script

Page 12: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Scripts (UnityScript)

• UnityScript is basically JavaScript• Other choices: C#, Boo• Assets=>Create=>JavaScript• Double-click to go into MonoDevelop– Two functions add automatically: Start and Update– Example (in Update)

• transform.Rotate(0,5,0);

• Debug output– print("Hey!" + tempVar);– Display at bottom of window, or in the output window.

Page 13: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Scripts, cont.

• Variable declarationpublic var myVar [: myType] [= myVal];public var direction : int = 99;

– Other modifiers:• static: visible to other scripts• private: can't be modified in Inspector.

• Basic Types: int, float, string, boolean• Enumerations:

enum myEnum {state1, state2};public var myState = myEnum.state1;

• Unity types: http://unity3d.com/support/documentation/ScriptReference/20_class_hierarchy.html

Page 14: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Scripts, cont.

• Classes– Foo.js • Creates a class named Foo• Variables in Foo.js are members, functions are

methods.

– Other way:class MyRecord extends XYZ{

public var name: integer;function doSomething() { /*…*/ }

};

Page 15: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Scripts, cont.

• Public Variables are visible (and changeable) in the Inspector– A great feature!– [Demo]– Note: you can change them at runtime (but it's

not permanent)

Page 16: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Classes, cont.

• Class must have same name as .js file (case-sensitive)• To add a script to a GameObject, derive from MonoBehavior• Constructor (function with same name as class) seems to be

called:– before Start method is called– When (re-)entering Player (after pressing stop)

• You seem to be able to reference (other) scripts anywhere in the project.

Page 17: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Classes, cont.

• Some other important methods / functions to overload:– Full List: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.html

– LateUpdate: Called after all Update's– OnMouseEnter [GUIElement's]– OnCollisionEnter• Called when this collider collides when another• Note: one collider must have a non-kinematic rigidbody

– OnCollisionStay– …

Page 18: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Accessing components

• The game object most likely has other components attached to it.

• E.g. You have a "Transform" component in Inspector– Access it in script like:• "transform.position.x"

– Note lower-case (this is the rule)

Page 19: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Messages

• FormatGameObject.SendMessage(string, param);

var go = GameObject.Find("Mine4087");go.SendMessage("explode", 14.3);

// (In any script(s) attached to Mine4087)function explode(timer : float){

// …}

• There is also a BroadcastMessage– Similar structure. Is sent to all child GameObjects recursively.

Page 20: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Scripting Misc.

• Time.deltaTime // Time since last Update.• Application.LoadLevel(x)– x is an integer (see BuildSettings) or string– Removes all other objects, unless…

• DontDestroyOnLoad(gameObject);– Keeps it from being destroyed on LoadLevel call

Page 21: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

GUI

• Made of GameObject's• Add a GUILayer component to (a) camera.• Make more components for each element– Make them children to the GUI layer component.

• Position:– (0,0,z): bottom-left– (1,1,z): top-right

Page 22: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Blender Review?

Page 23: Unity Overview Using Unity 3.5 (Free version) [1]: //docs.unity3d.com/Documentation/ScriptReference

Character animations

• From Blender:– Keyframe the skeleton– Open a DopeSheet pane• Select "Action Editor" from the drop-down• Click "New" or "+" to add current keys to a new action.

– The name you type will show up in Unity.