Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Game Project / Working with Unity


Published on

Published in: Education, Spiritual, Technology
  • Be the first to comment

Game Project / Working with Unity

  1. 1. Game Project<br />Unity<br />Petri Lankoski<br /><br />
  2. 2. Getting Started<br />Creating a new project<br />Select File -> New Project<br />Write the project name<br />Select (at least) the following Packages to the project<br />Character Controller<br />Scripts<br />Terrain Assets<br />Click Create Project<br />Getting Started with Unity<br />
  3. 3. Anatomy of the Unity Project<br />Getting Started with Unity<br />
  4. 4. Navigating in Unity<br />Getting Started with Unity<br />Move tool (shortcut: W)<br />Play Mode<br />Rotate tool (shortcut: E)<br />Hand tool (shortcut: Q)<br /><ul><li> click-drag to move camera
  5. 5. ALT click-drag to orbit camera around
  6. 6. CTR click-drag to zoom</li></ul>Scale tool (shortcut: R)<br />On scene view:<br /><ul><li> F to zoom to selected object
  7. 7. Hold right mouse to enable
  8. 8. ASWD movement
  9. 9. Q up, E down</li></li></ul><li>Anatomy of the Unity Project<br />Getting Started with Unity<br />
  10. 10. Working with the Scene<br />Add in-build plane<br />Game Objects -> Create Other -> Plane<br />Set Position <0,0,0><br />Set Scale to <10,10,10><br />Delete Main Camera<br />Getting Started with Unity<br />
  11. 11. Making Movable Camera<br />Hierarchy: select Main Camera<br />Project: Open Standard Assets / Prefabs<br />Drag First Person Controller to Hierarchy<br />Set Position to <0,2,0> if the First Person Controller drops thought the Plane<br />(Save Scene: File->Save Scene)<br />Getting Started with Unity<br />
  12. 12. Making Movable Camera<br />Getting Started with Unity<br />
  13. 13. Adding Details<br />Finder: Drop PlaneTexture.psd to Assets Folder<br />Adding Details to Plane<br />Hierarchy -> Popup Menu -> Create -> Material<br />Rename it to PlaneMaterial<br />Drop the PlaneTextureto the PlaneMaterial<br />Drop the PlaneMaterialto the Plane<br />Try Transparent/Diffuse shader<br />Texture should have transparency<br />Getting Started with Unity<br />Shader<br />Texture<br />
  14. 14. Adding Details<br />Light: Game Object -> Create Other -> Directional Light<br />Move and rotate the light in Scene view or in Inspector<br />Add cylinder on the plain; add material and texture to the cube<br />Getting Started with Unity<br />Drag with <br />mouse<br />Rotate<br />Move<br />
  15. 15. Adding Sounds<br />Finder: drop a sound file to Assets folder<br />Add an Game Object to Scene<br />Drag and Drop the sound file to the Game Object<br />Rolloff factor determines how fast sound fades when distance grows<br />Getting Started with Unity<br />
  16. 16. Adding Animated Model<br />Finder: Drop the model (e.g., Abby.fbx) to Assets folder<br />Drag and Drop the model to Scene (or Hierarchy)<br />Set Position <8,1.1,0)<br />Getting Started with Unity<br />
  17. 17. Test the Model<br />Getting Started with Unity<br />
  18. 18. Setting Up Bone Animations<br />The Model Abby has different animations:<br />Idle: 1-200<br />Idle: 201-390<br />Idle Action: 391-660<br />Walk: 819-898<br />Etc.<br />We need to split animations to use them in Unity<br />Getting Started with Unity<br />
  19. 19. Creating Prefab<br />Create a New Scene<br />File -> New Scene<br />Add Plane and scale it bigger (x & z)<br />Rename “Abby” to “Abby Model” (project view)<br />Create Abby prefab<br />Project Popup -> Create -> Prefab<br />Rename “New Prefab” to “Abby”<br />Drag-and-drop Abby Model to Abby<br />Getting Started with Unity<br />
  20. 20. Creating Prefab<br />Adding control scripts to Abby<br />Drag-and-drop ThirdPersonController to Abby<br />Change values of CharacterController of Abby<br />Height: 1.7<br />Radius: 0.3<br />Add animations to the scripts<br />Add SmootFollow to Main Camera<br />Drag-and-drop Abby to Scene view<br />Make her stand on the plain<br />Drag-and-drop Abby to Main Camera/SmoothFollow/Target<br />Getting Started with Unity<br />
  21. 21. xx<br />Getting Started with Unity<br />
  22. 22. xx<br />Getting Started with Unity<br />
  23. 23. Adding New Animation Control<br />Create new C# script AbbyAnim<br />Attach the script to Abby (on Scene view)<br />Add idle action animation clip to the Abby/AbbyAnim<br />Apply changes to prefab<br />Getting Started with Unity<br />More about character animation, <br /><br />
  24. 24. public class AbbyAnim : MonoBehaviour {<br />private Animation _animation;<br />public AnimationClip action;<br />void Awake() {<br />_animation = GetComponent(typeof(Animation)) as Animation;<br />if (! _animation) { Debug.LogError(“…”); }<br />if (! action) { Debug.LogError(“…”); return;}<br />_animation[].wrapMode = WrapMode.Once;<br />}<br />…<br />Getting Started with Unity<br />
  25. 25. …<br />void Update() {<br />if(Input.GetKey(“z”) {<br />_animation.Play(;<br />}<br />}<br />}<br />Getting Started with Unity<br />
  26. 26. Mono Behavior<br />Can be attached to game objects<br />Unity Calls MonoBehavior<br />Initialization<br />Awake(): called for every MonoBbehavior<br />Start(): called for every MonoBehaviour after all the Awake()s<br />Game Loop calls<br />Update(): called in every frame, most things happens here<br />LateUpdate(): called after every Update()s are exceted. Use for, e.g., follow camera<br />FixedUpdate(): use for physics thing, e.g., RagDoll handling<br />OnGUI(), for GUI drawing, can be called several times in each frame <br />Other useful things: Invoke(), InvokeRepeating(), StartCouroutine()<br />Getting Started with Unity<br />
  27. 27. User Interface<br />public class ExampleGUI : MonoBehaviour {<br />public GUISkingSkin;<br />public string infoText = "”;<br />private boolshowThingies;<br />void Start() {<br />if(gSkin==null) { Debug.LogError(“ gSkin is not set”); }<br />showThingies = false;<br /> }<br />}<br />Getting Started with Unity<br />
  28. 28. User Interface…<br />void OnGUI() {<br /> = gSkin; // Seting skin for changins how GUI looks in inspector<br />GUI.matrix = Matrix4x4.TRS(, Quaternion.identity,<br />new Vector3(Screen.width / 1280.0f, Screen.height / 854.0f, 1));<br />GUILayout.BeginArea (new Rect (1100, 750, 100, 100));<br />if(showThingies) {<br />if(GUILayout.Button ("Hide")) { showThingies = !showThingies; }<br /> }<br /> else {<br />if(GUILayout.Button ("Show")) { showThingies = !showThingies; }<br /> }<br />GUILayout.EndArea ();<br />if(showThingies) { <br />GUI.Label(newRect (600, 400, 200, 200), infoText, "blackBG");<br />} <br />Getting Started with Unity<br />
  29. 29. User Interface<br />Create a game object for attaching GUI script<br />Game Object->Create Empty<br />Rename the new object to, e.g., GUI Cube<br />Drag-and-drop ExampleGUI script to GUI Cube<br />Create GUI Skin<br />Project -> popup -> GUI Skin<br />Drag and drop the skin to ExampleGUI : GSkin<br />Getting Started with Unity<br />
  30. 30. User Interface<br />Experiment with GUI Skin settings<br />Play to see how the settings changes GUI<br />Getting Started with Unity<br />
  31. 31. Models and Animations<br />Characters<br />15-60 bones<br />Hierarchy!<br />Consistent naming (the same names for same type of things)<br />2500-5000 triangles<br />Textures<br />Optimal size: 2nx2m (1x1, 2x2, …, 128x256, … 256x256, …, 256x1024, …, 1024x1024,)<br />In some cases SoftImage does texture optimizing <br />Optimal size: small as possible<br />Older cards do not support over 1024x1024<br />Getting Started with Unity<br />
  32. 32. Material – Shader – Texture<br />Material defines<br />Shader<br />Defines method to render an object, texture properties, etc.<br />Texture(s)<br />Color definitions<br />Other assets<br />E.g., cubemap required for rendering<br />Getting Started with Unity<br />
  33. 33. Models and Animations<br />Object needs to be drawn for every of its texture<br />Object with 4 textures will be draw 4 times<br />Combine textures in SoftImage<br />Use different textures only if you, e.g., need different shaders<br />Unity and SoftImage have different shaders<br />Use simplest possible shader in Unity<br />Opt for shaders without bumbs, transparencies unless you use these<br />Getting Started with Unity<br />
  34. 34. Code Optimizing<br /><ul><li>Keep Update(), FixedUpdate(), LateUpdate(), OnGUI() clean</li></ul>Avoid object lookups, e.g., GameObject.Find() calls within these<br />Cache lookup results when possible<br />Use MonoBehaviour.enabled to disable/enable MonoBehavior if you do not want to execute Update(), …<br />MonoBehaviour.Invoke(), MonoBehaviour.InvokeRepeating() and Couroutines are alternative to Update()<br />Functionality is not needed to execute in every frame<br />E.g., use InvokeRepeating() to execute of function for every 0.5s<br />Do not add empty Update(), FixedUpdate(), LateUpdate(), OnGUI() <br />Call overhead!<br />Getting Started with Unity<br />
  35. 35. Version Control<br />External version control with Pro<br />Needs to be enabled from Edit->Project Settings->Editor<br />Set up the system:<br />CVS, Perforce, Subversion, …<br />Binary files, (textures, models, sounds) do not work work well with these<br />Unity Pro project will be incompatible with Unity<br />DropBox as version control<br />Drop the project folder to a DropBox folder to check in a version and vice versa<br />CVS, Perforce, Subversion for version control for scripts<br />Unity and Unity Pro projects will be compable<br />Unity Pro only features will be automatically disabled in Unity<br />Regular backup (e.g., zip the project folder)<br />Archive backups to have snapshop of the project to rollback<br />Getting Started with Unity<br />
  36. 36. Terrain Editor<br />Terrain->Create Terrain<br />Getting Started with Unity<br />More about Terrain Editor,<br />
  37. 37. Terrain Editor…<br />Getting Started with Unity<br />
  38. 38. Terrain Editor…<br />Getting Started with Unity<br />
  39. 39. Terrain Editor…<br />Getting Started with Unity<br />
  40. 40. Terrain Editor…<br />Getting Started with Unity<br />
  41. 41. Terrain Editor…<br />Getting Started with Unity<br />
  42. 42. More Information<br />Unity manual <br /><br />Unity scripting reference<br /><br />Unity Scripts and Tips Wiki<br /><br />Unity Tutorials<br /><br />Lies and Seductions source code<br /><br />Getting Started with Unity<br />