Game ProjectUnityPetri Lankoskiaalto.fi
Getting StartedCreating a new projectSelect File -> New ProjectWrite the project nameSelect (at least) the following Packages to the projectCharacter ControllerScriptsTerrain AssetsClick Create ProjectGetting Started with Unity
Anatomy of the Unity ProjectGetting Started with Unity
Navigating in UnityGetting Started with UnityMove tool (shortcut: W)Play ModeRotate tool (shortcut: E)Hand tool (shortcut: Q) click-drag to move camera
 ALT click-drag to orbit camera around
 CTR click-drag to zoomScale tool (shortcut: R)On scene view: F to zoom to selected object
 Hold right mouse to enable
 ASWD movement
 Q up, E downAnatomy of the Unity ProjectGetting Started with Unity
Working with the SceneAdd in-build planeGame Objects -> Create Other -> PlaneSet Position <0,0,0>Set Scale to <10,10,10>Delete Main CameraGetting Started with Unity
Making Movable CameraHierarchy: select Main CameraProject: Open Standard Assets / PrefabsDrag First Person Controller to HierarchySet Position to <0,2,0> if the First Person Controller drops thought the Plane(Save Scene: File->Save Scene)Getting Started with Unity
Making Movable CameraGetting Started with Unity
Adding DetailsFinder: Drop PlaneTexture.psd to Assets FolderAdding Details to PlaneHierarchy -> Popup Menu -> Create -> MaterialRename it to PlaneMaterialDrop the PlaneTextureto the PlaneMaterialDrop the PlaneMaterialto the PlaneTry Transparent/Diffuse shaderTexture should have transparencyGetting Started with UnityShaderTexture
Adding DetailsLight: Game Object -> Create Other -> Directional LightMove and rotate the light in Scene view or in InspectorAdd cylinder on the plain; add material and texture to the cubeGetting Started with UnityDrag with mouseRotateMove
Adding SoundsFinder: drop a sound file to Assets folderAdd an Game Object to SceneDrag and Drop the sound file to the Game ObjectRolloff factor determines how fast sound fades when distance growsGetting Started with Unity
Adding Animated ModelFinder: Drop the model (e.g., Abby.fbx) to Assets folderDrag and Drop the model to Scene (or Hierarchy)Set Position <8,1.1,0)Getting Started with Unity
Test the ModelGetting Started with Unity
Setting Up Bone AnimationsThe Model Abby has different animations:Idle: 1-200Idle: 201-390Idle Action: 391-660Walk: 819-898Etc.We need to split animations to use them in UnityGetting Started with Unity
Creating PrefabCreate a New SceneFile -> New SceneAdd Plane and scale it bigger (x & z)Rename “Abby” to “Abby Model” (project view)Create Abby prefabProject Popup -> Create -> PrefabRename “New Prefab” to “Abby”Drag-and-drop Abby Model to AbbyGetting Started with Unity
Creating PrefabAdding control scripts to AbbyDrag-and-drop ThirdPersonController to AbbyChange values of CharacterController of AbbyHeight: 1.7Radius: 0.3Add animations to the scriptsAdd SmootFollow to Main CameraDrag-and-drop Abby to Scene viewMake her stand on the plainDrag-and-drop Abby to Main Camera/SmoothFollow/TargetGetting Started with Unity
xxGetting Started with Unity
xxGetting Started with Unity
Adding New Animation ControlCreate new C# script AbbyAnimAttach the script to Abby (on Scene view)Add idle action animation clip to the Abby/AbbyAnimApply changes to prefabGetting Started with UnityMore about character animation, http://unity3d.com/support/documentation/Manual/Character-Animation.html
public class AbbyAnim : MonoBehaviour {private Animation _animation;public AnimationClip action;void Awake() {_animation = GetComponent(typeof(Animation)) as Animation;if (! _animation) { Debug.LogError(“…”); }if (! action) { Debug.LogError(“…”); return;}_animation[action.name].wrapMode = WrapMode.Once;}…Getting Started with Unity
…void Update() {if(Input.GetKey(“z”) {_animation.Play(action.name);}}}Getting Started with Unity
Mono BehaviorCan be attached to game objectsUnity Calls MonoBehaviorInitializationAwake(): called for every MonoBbehaviorStart(): called for every MonoBehaviour after all the Awake()sGame Loop callsUpdate(): called in every frame, most things happens hereLateUpdate(): called after every Update()s are exceted. Use for, e.g., follow cameraFixedUpdate(): use for physics thing, e.g., RagDoll handlingOnGUI(), for GUI drawing, can be called several times in each frame Other useful things: Invoke(), InvokeRepeating(), StartCouroutine()Getting Started with Unity
User Interfacepublic class ExampleGUI : MonoBehaviour {public GUISkingSkin;public string infoText = "”;private boolshowThingies;void Start() {if(gSkin==null)  { Debug.LogError(“ gSkin is not set”); }showThingies = false;	}}Getting Started with Unity
User Interface…void OnGUI() {GUI.skin = gSkin; // Seting skin for changins how GUI looks in inspectorGUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,new Vector3(Screen.width / 1280.0f, Screen.height / 854.0f, 1));GUILayout.BeginArea (new Rect (1100, 750, 100, 100));if(showThingies) {if(GUILayout.Button ("Hide")) { showThingies = !showThingies; }		}		else {if(GUILayout.Button ("Show")) { showThingies = !showThingies; }		}GUILayout.EndArea ();if(showThingies) { GUI.Label(newRect (600, 400, 200, 200), infoText, "blackBG");} Getting Started with Unity
User InterfaceCreate a game object for attaching GUI scriptGame Object->Create EmptyRename the new object to, e.g., GUI CubeDrag-and-drop ExampleGUI script to GUI CubeCreate GUI SkinProject -> popup -> GUI SkinDrag and drop the skin to ExampleGUI : GSkinGetting Started with Unity
User InterfaceExperiment with GUI Skin settingsPlay to see how the settings changes GUIGetting Started with Unity
Models and AnimationsCharacters15-60 bonesHierarchy!Consistent naming (the same names for same type of things)2500-5000 trianglesTexturesOptimal size: 2nx2m (1x1, 2x2, …, 128x256, … 256x256, …, 256x1024, …, 1024x1024,)In some cases SoftImage does texture optimizing Optimal size: small as possibleOlder cards do not support over 1024x1024Getting Started with Unity
Material – Shader – TextureMaterial definesShaderDefines method to render an object, texture properties, etc.Texture(s)Color definitionsOther assetsE.g., cubemap required for renderingGetting Started with Unity
Models and AnimationsObject needs to be drawn for every of its textureObject with 4 textures will be draw 4 timesCombine textures in SoftImageUse different textures only if you, e.g., need different shadersUnity and SoftImage have different shadersUse simplest possible shader in UnityOpt for shaders without bumbs, transparencies unless you use theseGetting Started with Unity
Code OptimizingKeep Update(), FixedUpdate(), LateUpdate(), OnGUI() cleanAvoid object lookups, e.g., GameObject.Find() calls within theseCache lookup results when possibleUse MonoBehaviour.enabled to disable/enable MonoBehavior if you do not want to execute Update(), …MonoBehaviour.Invoke(), MonoBehaviour.InvokeRepeating() and Couroutines are alternative to Update()Functionality is not needed to execute in every frameE.g., use InvokeRepeating() to execute of function for every 0.5sDo not add empty Update(), FixedUpdate(), LateUpdate(), OnGUI() Call overhead!Getting Started with Unity
Version ControlExternal version control with ProNeeds to be enabled from Edit->Project Settings->EditorSet up the system: http://unity3d.com/support/documentation/Manual/ExternalVersionControlSystemSupport.htmlCVS, Perforce, Subversion, …Binary files, (textures, models, sounds) do not work work well with theseUnity Pro project will be incompatible with UnityDropBox as version controlDrop the project folder to a DropBox folder to check in a version and vice versaCVS, Perforce, Subversion for version control for scriptsUnity and Unity Pro projects will be compableUnity Pro only features will be automatically disabled in UnityRegular backup (e.g., zip the project folder)Archive backups to have snapshop of the project to rollbackGetting Started with Unity
Terrain EditorTerrain->Create TerrainGetting Started with UnityMore about Terrain Editor, http://unity3d.com/support/documentation/Manual/Terrains.html
Terrain Editor…Getting Started with Unity
Terrain Editor…Getting Started with Unity

Game Project / Working with Unity

  • 1.
  • 2.
    Getting StartedCreating anew projectSelect File -> New ProjectWrite the project nameSelect (at least) the following Packages to the projectCharacter ControllerScriptsTerrain AssetsClick Create ProjectGetting Started with Unity
  • 3.
    Anatomy of theUnity ProjectGetting Started with Unity
  • 4.
    Navigating in UnityGettingStarted with UnityMove tool (shortcut: W)Play ModeRotate tool (shortcut: E)Hand tool (shortcut: Q) click-drag to move camera
  • 5.
    ALT click-dragto orbit camera around
  • 6.
    CTR click-dragto zoomScale tool (shortcut: R)On scene view: F to zoom to selected object
  • 7.
    Hold rightmouse to enable
  • 8.
  • 9.
    Q up,E downAnatomy of the Unity ProjectGetting Started with Unity
  • 10.
    Working with theSceneAdd in-build planeGame Objects -> Create Other -> PlaneSet Position <0,0,0>Set Scale to <10,10,10>Delete Main CameraGetting Started with Unity
  • 11.
    Making Movable CameraHierarchy:select Main CameraProject: Open Standard Assets / PrefabsDrag First Person Controller to HierarchySet Position to <0,2,0> if the First Person Controller drops thought the Plane(Save Scene: File->Save Scene)Getting Started with Unity
  • 12.
  • 13.
    Adding DetailsFinder: DropPlaneTexture.psd to Assets FolderAdding Details to PlaneHierarchy -> Popup Menu -> Create -> MaterialRename it to PlaneMaterialDrop the PlaneTextureto the PlaneMaterialDrop the PlaneMaterialto the PlaneTry Transparent/Diffuse shaderTexture should have transparencyGetting Started with UnityShaderTexture
  • 14.
    Adding DetailsLight: GameObject -> Create Other -> Directional LightMove and rotate the light in Scene view or in InspectorAdd cylinder on the plain; add material and texture to the cubeGetting Started with UnityDrag with mouseRotateMove
  • 15.
    Adding SoundsFinder: dropa sound file to Assets folderAdd an Game Object to SceneDrag and Drop the sound file to the Game ObjectRolloff factor determines how fast sound fades when distance growsGetting Started with Unity
  • 16.
    Adding Animated ModelFinder:Drop the model (e.g., Abby.fbx) to Assets folderDrag and Drop the model to Scene (or Hierarchy)Set Position <8,1.1,0)Getting Started with Unity
  • 17.
    Test the ModelGettingStarted with Unity
  • 18.
    Setting Up BoneAnimationsThe Model Abby has different animations:Idle: 1-200Idle: 201-390Idle Action: 391-660Walk: 819-898Etc.We need to split animations to use them in UnityGetting Started with Unity
  • 19.
    Creating PrefabCreate aNew SceneFile -> New SceneAdd Plane and scale it bigger (x & z)Rename “Abby” to “Abby Model” (project view)Create Abby prefabProject Popup -> Create -> PrefabRename “New Prefab” to “Abby”Drag-and-drop Abby Model to AbbyGetting Started with Unity
  • 20.
    Creating PrefabAdding controlscripts to AbbyDrag-and-drop ThirdPersonController to AbbyChange values of CharacterController of AbbyHeight: 1.7Radius: 0.3Add animations to the scriptsAdd SmootFollow to Main CameraDrag-and-drop Abby to Scene viewMake her stand on the plainDrag-and-drop Abby to Main Camera/SmoothFollow/TargetGetting Started with Unity
  • 21.
  • 22.
  • 23.
    Adding New AnimationControlCreate new C# script AbbyAnimAttach the script to Abby (on Scene view)Add idle action animation clip to the Abby/AbbyAnimApply changes to prefabGetting Started with UnityMore about character animation, http://unity3d.com/support/documentation/Manual/Character-Animation.html
  • 24.
    public class AbbyAnim: MonoBehaviour {private Animation _animation;public AnimationClip action;void Awake() {_animation = GetComponent(typeof(Animation)) as Animation;if (! _animation) { Debug.LogError(“…”); }if (! action) { Debug.LogError(“…”); return;}_animation[action.name].wrapMode = WrapMode.Once;}…Getting Started with Unity
  • 25.
    …void Update() {if(Input.GetKey(“z”){_animation.Play(action.name);}}}Getting Started with Unity
  • 26.
    Mono BehaviorCan beattached to game objectsUnity Calls MonoBehaviorInitializationAwake(): called for every MonoBbehaviorStart(): called for every MonoBehaviour after all the Awake()sGame Loop callsUpdate(): called in every frame, most things happens hereLateUpdate(): called after every Update()s are exceted. Use for, e.g., follow cameraFixedUpdate(): use for physics thing, e.g., RagDoll handlingOnGUI(), for GUI drawing, can be called several times in each frame Other useful things: Invoke(), InvokeRepeating(), StartCouroutine()Getting Started with Unity
  • 27.
    User Interfacepublic classExampleGUI : MonoBehaviour {public GUISkingSkin;public string infoText = "”;private boolshowThingies;void Start() {if(gSkin==null) { Debug.LogError(“ gSkin is not set”); }showThingies = false; }}Getting Started with Unity
  • 28.
    User Interface…void OnGUI(){GUI.skin = gSkin; // Seting skin for changins how GUI looks in inspectorGUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,new Vector3(Screen.width / 1280.0f, Screen.height / 854.0f, 1));GUILayout.BeginArea (new Rect (1100, 750, 100, 100));if(showThingies) {if(GUILayout.Button ("Hide")) { showThingies = !showThingies; } } else {if(GUILayout.Button ("Show")) { showThingies = !showThingies; } }GUILayout.EndArea ();if(showThingies) { GUI.Label(newRect (600, 400, 200, 200), infoText, "blackBG");} Getting Started with Unity
  • 29.
    User InterfaceCreate agame object for attaching GUI scriptGame Object->Create EmptyRename the new object to, e.g., GUI CubeDrag-and-drop ExampleGUI script to GUI CubeCreate GUI SkinProject -> popup -> GUI SkinDrag and drop the skin to ExampleGUI : GSkinGetting Started with Unity
  • 30.
    User InterfaceExperiment withGUI Skin settingsPlay to see how the settings changes GUIGetting Started with Unity
  • 31.
    Models and AnimationsCharacters15-60bonesHierarchy!Consistent naming (the same names for same type of things)2500-5000 trianglesTexturesOptimal size: 2nx2m (1x1, 2x2, …, 128x256, … 256x256, …, 256x1024, …, 1024x1024,)In some cases SoftImage does texture optimizing Optimal size: small as possibleOlder cards do not support over 1024x1024Getting Started with Unity
  • 32.
    Material – Shader– TextureMaterial definesShaderDefines method to render an object, texture properties, etc.Texture(s)Color definitionsOther assetsE.g., cubemap required for renderingGetting Started with Unity
  • 33.
    Models and AnimationsObjectneeds to be drawn for every of its textureObject with 4 textures will be draw 4 timesCombine textures in SoftImageUse different textures only if you, e.g., need different shadersUnity and SoftImage have different shadersUse simplest possible shader in UnityOpt for shaders without bumbs, transparencies unless you use theseGetting Started with Unity
  • 34.
    Code OptimizingKeep Update(),FixedUpdate(), LateUpdate(), OnGUI() cleanAvoid object lookups, e.g., GameObject.Find() calls within theseCache lookup results when possibleUse MonoBehaviour.enabled to disable/enable MonoBehavior if you do not want to execute Update(), …MonoBehaviour.Invoke(), MonoBehaviour.InvokeRepeating() and Couroutines are alternative to Update()Functionality is not needed to execute in every frameE.g., use InvokeRepeating() to execute of function for every 0.5sDo not add empty Update(), FixedUpdate(), LateUpdate(), OnGUI() Call overhead!Getting Started with Unity
  • 35.
    Version ControlExternal versioncontrol with ProNeeds to be enabled from Edit->Project Settings->EditorSet up the system: http://unity3d.com/support/documentation/Manual/ExternalVersionControlSystemSupport.htmlCVS, Perforce, Subversion, …Binary files, (textures, models, sounds) do not work work well with theseUnity Pro project will be incompatible with UnityDropBox as version controlDrop the project folder to a DropBox folder to check in a version and vice versaCVS, Perforce, Subversion for version control for scriptsUnity and Unity Pro projects will be compableUnity Pro only features will be automatically disabled in UnityRegular backup (e.g., zip the project folder)Archive backups to have snapshop of the project to rollbackGetting Started with Unity
  • 36.
    Terrain EditorTerrain->Create TerrainGettingStarted with UnityMore about Terrain Editor, http://unity3d.com/support/documentation/Manual/Terrains.html
  • 37.
  • 38.

Editor's Notes

  • #5 Unity Project in the filesystem is a folder that contains folders Assets, Library, and Temp. Models, textures, scripts etc. goes to Assets folder. Assets folder can contain subfolders. Just drag and drop in Finder assets were you want to put them.BUT, rename things in Unity, NOT in Finder, because renaming in Finder will break dependencies in Unity.
  • #8 Test by hitting PLAY. You can test and see your game in Game window . Controls: ASDW or cursor keys + mouse
  • #13 By default, as Play Automatically is selected, the animations of the model are played, but we do now we do not have any control over them