Unity Tutorial

by guitarrapc
+

Ref: http://tutorial.unity3d.jp/ && https://github.com/unity3d-jp/FirstTutorial/wiki

( Updated 21 minutes ago )

Reference https://github.com/unity3d-jp/FirstTutorial/wiki for Unity Project tutorial.

Done

Roll-a-Ball

  • [x] Use Unity 5.3.x Pro (latest as possible)
    • [x] Open with different version of Unity
  • [x] Commit with GitHub
  • [x] Understand Unity Project
  • [x] Understand what Unity Scene
  • [x] Editor Layout
    • Tutorial 0
    • [x] Understand what each layout section name is
      • Scene View
      • Game View
      • Inspector View
      • Hierarchy View
      • Project Browser
    • [x] Modify Project Browser for Single column
    • [x] Understand how to move Scene View
      • Understand each icon meaning
      • Understand Mouse short cut
    • [x] Understand template
    • [x] Change and save preference
    • [x] Override existing
    • [x] Temporary define Prefered style of Layout for Hierarchy and Inspector
    • [x] Check others layout
      • neuecc
    • [x] Unity Scene cannot share with others.
  • [x] GameObject
    • Tutorial 1
    • [x] Add Item to Hierarchy
    • [x] Copy Item
    • [x] Move Item in Scene view
      • [x] Understand Position
    • [x] Adjust position in Scene view by mouse
    • [x] Adjust position in Scene view by Inspector
    • [x] Add Material to GameObject by Project Browser to Hierarchy
      • [x] Change Material Aldibo Text
      • [x] Change Material Aldibo Colour
    • [x] Scale GameObject
      • [x] Understand Scale
    • [x] Rotate GameObject
    • [x] Sort GameObjects
      • [x] Create Folder
      • [x] Move GameObject and add it to Folder at Hierarchy
    • [x] Set Stage as Static Object
      • Improve Performance
      • Apply to Child Items
    • Tutorial 2
    • [x] Add cube
    • [x] Add Compornent
    • [x] Add RigidBody
      • [x] What RigidBody is
      • [x] What change if RigidBody is added to GameObject
      • [x] How to check Unity API
  • [x] Play
    • Tutorial 2
    • [x] Understand Play
    • [x] Change Editor Colour when Playing
      • Edit > Preference > Colors > Playmode tint
    • [x] How to
  • [x] Script
    • Tutorial 2
    • [x] How to Add Script
      • Project Browser > Add Script > Csharp
    • [x] Use Script Editor as Visual Studio 2015 Enterprise.
      • [x] Switch with Mono Develop
      • [x] Understand VSTU integration check by Edit > Preference > External Tools and Help > About Unity.
      • [x] Install VSTU 2.2 as it were latest.
    • [x] Add Script to Compornent
    • [x] What FixedUpdate() Method is
    • [x] What Update() Method is
    • [x] How to expose parameter to Inspector
      • [x] What Public Field
      • [x] Why Property couldn't expose paramter to Inspector
      • [x] How to use Property as Field
      • [x] Pass paremter from Inspector to Script
  • [x] Script Methods
    • Tutorial 2
    • [x] What is Input
    • [x] Where to handle Input Key, Mouse and JoyStick Binding
      • Need to input when Game Schene is active,
    • [x] What GetAxis() is. Why string constructor is fixed. (.... Why Unity doesn't use Enum to pass...?)
  • [x] Camera
    • Tutorial 3
    • Add Camera to GameObject
      • Won't be controllable:)
    • Create component, Script, to trace Player position
      • as FPS
      • as TPS
  • [x] Prefab
    • Tutorial 4
    • [x] What Prefab is.
      • Unity - Prefab
      • Instance of Asset?
      • All GameObject created from Prefab can be handle as Class Instance.
      • It means if you add some material to a Prefab, not to GameObject, then all clone items created from a Prefab will be apply same change.
      • After you create instance of Prefab, you can set each instance of GameObject position, rotation and others.
    • [x] Why Prefab?
      • Because as Object-Oriented Programing have Class-Instance, Prefab is samething in Unity GameObject.
    • [x] Prefab rule
      • [x] Should Position / Rotation set to be 0?
        • This is because Prefab is template of GameObject and copy will create based on Prefab.
    • [x] Create Prefab
      • Create Folder in Projet Browser -> then drag Hierarchy item to ProjectBrowser Folder
    • [x] Position Prefab instance GameObject
    • [x] Add Colision detection by Trigger
  • [x] Canvas
    • Tutorial 5
    • [x] Create Canvas
      • Now Canvas can contains UI item to draw item inside
      • Automatically create EventSystem GameObject
    • [x] UI Scale mode to be Scale with Screen Size
    • Should be better move Scene view from GAmeView like to near the Canvas. This is because GameView will draw by Canvas + SceneView Item.
  • [x] Text
    • Tutorial 5
    • [x] Create Text object inside Canvas
    • [x] Rocate Text by Scaling position of Canvas
    • [x] Change Scale
    • [x] Change Font Size
    • [x] Change Label
  • [x] GameController
    • Tutorial 5
    • Message Dispatcher from Event to the Text
    • [x] Create Empty
    • [x] Taging with GameController
    • [x] Apply Item Tag to Prefab item Item.
      • This apply tag change to all instantiate items.
    • [x] Create GameController Script
      • [x] Count up Taged items and apply change to Label.
        • GameObject.FindGameObjectsWithTag (<string>tagName).Length
      • [x] Create public field to accept Label GameObject binding with Script.
      • [x] Apply count change to label.text.
    • [x] Bind Script to GameController
    • [x] Bind Lebel to GameController Script Public Field by drag and drop Label in Hieralchy -> GameController Inspector > GameController public Field.
  • [x] Tag and Layer
    • Tutorial 5
    • [x] Add Tag by Menu bar > Edit > Tags and Layer add Tags by + and set name.
    • Add Item Tag.
  • [x] Position fix
    • If you had set GameObject inside Empty, then Empty is Parent and items inside will be children.
    • All Children position is based on Parent position.
      • This means if Parent position is 10, 10, 10 then even if you sat children position 0,0,0 world position will be calculated from parent position 10,10,10.
    • Would be better always set parent as 0, 0, 0?
  • [x] Active
    • Tutorial 6
    • All GameObject have property Active
      • If you set this as InActive, then GameObject will not be show in GameView.
      • So it can be use for timing when to show GameObject.
    • [x] Create Lable for Finish -> FinishLabel.
      • [x] Set position and default text
      • [x] Set Item as InActive at Inspector (means default)
    • [x] create public field to GameController to accept GameObject of FinishLabel
      • [x] Bind FinishLabel to the Script from Inspector
    • [x] Add Condition when count == 0, WinnerLabel is Active.
  • [x] Bright Materia
    • Tutorial 7
    • [x] Create material at Project Browser
    • [x] Name it as DangerWallMaterial
    • [x] Set Albedo colour as Red
    • [x] Set Emission colour as Red
  • [x] Create GameObject for Trap
    • Tutorial 7
    • [x] Create Cube Object as DangerWall
    • [x] Attach DangerWAllMaterial to DangerWall GameObject
    • [x] Set it as Prefab
    • [x] Instantiate items from prefab
    • [x] Create Empty GameObject as Traps, and set scale as 1,1,1. position as 0,0,0
    • [x] Attach all DangerWall gameobjects inside Traps
    • [x] Set Traps as Static, as it were never move.
  • [x] Light
    • Tutorial 7
    • [x] Change Brightness
      • Select DirectionalLight and set Intensity from 1.0 to 0.7 (Can be make 0, looks like night effect!)
  • [x] SceneManager
    • Tutorial 7
    • [x] Create DangerWallRestartScene Script to restart scene when player collision danger wall.
    • [x] Detect Collision by void OnCollisionEnter(Collision hit)
    • [x] Change Application as it were depricated. Application.LoadLevel(Application.loadedLevel);
  • [x] Build for Standalone
    • Windows
  • [x] Run Build Game

Additional

  • [x] Add TimeLimit
    • Timer.deltaTime
  • [x] Add GameOver
    • Label + TimeLimit
  • [x] Add Mouse Move X/Y

2D Shooting

  • [x] Player Settings
    • Before started
    • Modify Player Resolution Settings
    • Edit > Project Preference > PlayerSettings > Resolution and Presentation
    • 600 x 400
  • [x] Game View Resolution
  • [x] Sprite
    • Tutorial 1
    • What is Sprite : http://docs.unity3d.com/ja/current/ScriptReference/Sprite.html
      • Spirite Object in 2D Game Play
    • [x] Texture Type
      • Should set as Sprite
    • [x] Sprite Mode
      • Multiple : If Texture contains more than one sprite
      • Single : If Texture contains only one sprite
    • [x] Pixcels per Units
      • Unity of measure in Unity == Unit
      • 1 Unit == 1m
      • Pixcels per units express relationship with Pixcel and Unit.
      • Pixcels Per Unit == 1
        • 1 Pixcel size = 1 Unit Size
      • Pixcels Per Unit == 100
        • 100 Pixcel = 1 Unity
  • [x] Sprite Editor
    • Tutorial 1
    • 1 Texture would be contains more than 1 Sprite because of it's efficiecy.
      • Problem is "How to devide sprite for each GameObject from 1 Texture."
      • Resolution is set Sprite area in Texture when import texture.
    • [x] Open Sprite Editor from Inspector View
    • [x] Select Slice on left top.
      • [x] Type == Automatic means automatically slice Sprite.
      • [x] Change Type to Grid by cell Size
      • [x] Set Slice size in Pixcel size than run slice.
      • [x] Apply to chang takes effects.
  • [x] Animation
    • Tutorial 1
    • [x] Create Animation
      • Drag and Drop > Select Folder name to be created.
    • Change Hierarchy GameObject Name to Player, change Animation name to Normal, Player.
    • [x] Create Animations
      • [x] Create Player
      • [x] Create Enemy
      • [x] Create Bullet (Only Sprite)
      • [x] Create Explode
    • [x] Create Prefab.
    • [x] Set All Prefab Position to 0,0,0 (actually only x and y. z always 0 in 2D mode)
    • [x] Remove Apply Root Motion for 2D.
      • It doesn't use in 2D and will be break what you desire.
  • [x] Rigidbody2D
    • Tutorial 2
    • RigidBody for 2D
    • [x] Set Gravity Scale to 0
    • Script to move Player
      • [x] Add Component > C# Script
      • [x] Vector2
        • Tutorial 2
        • As this game is 2D, you don't need to use Vector3.
        • Vector2 can be determine by Input. On this time use Keyboard.
      • [x] Normalize Vector
        • With 2D, direction can be determine by Unit Vector.
        • This can be calculate from normalized reaonly property like Vector2(x, y).normalized
        • normalized means treat magnitude as always 1. so you can just obtain which direction it is.
      • [x] Velocity
        • Now you can handle Direction. Velocity is rate for Acceralate.
          • Difference between Velocity property and AddForce() method is resistor.
          • As Velocity is just a accelarate value, means there's no resistor condideration == max speed from first step.
          • OTH, AddForce() is method. It add acceralate to object. base object velocity is 0, so AddForce() will slowly add force. It's like there are resistor.
  • [x] Camera
    • Tutorial 2
    • [x] Projection
      • As this is 2D, don't need to be Perspective. Change Projection to be Orthographic
      • Change Size to be 3 to limit stage size.
  • [x] Add Bullet
    • Tutorial 3
    • [x] Add RigitBody2D to the bullet.
    • [x] Set Bullet position in SceneView and drag to container gameobject. (PlayerBullet)
    • [x] Create Prefab for contaier object PlayerBullet.
    • [x] Create Script and write as bullet just go up when game start.
      • Attach Script to PlayerBullet Prefab.
      • gamestart : Start()
      • set speed : public int Speed = 10;
      • for bullet, that script attached : gameobject.GetComponent().velocity
      • just go up : .velocity = transform.up.normalized * Speed;
  • [x] Coroutine
    • Tutorial 3
    • Unity - Cotoutine
    • IEnumerator to control function execution timing by user script.
      • As there are Update() Method to call function in every frame, and can be easily stop Game World because of function cannot be finished in the flame AND ALSO Update() will call too match time and hard to control when to call next.
      • So a lot of times Unity recomend to use IEnumerator Start(){ AnyFunction} to call you function with yield return.
      • As there are Enumerator in C#, Coroutine will return yield execution result and continus on next.
      • You can controll interval of yield return with ``yield return new WaitForSeconds(float)```, besides Update() can't be controllable.
      • Just remember, Coroutine is not silver bullet. Don't do like IEnumerator Update(). just use IEnumerator Start(), and be sure to be finish function as soon as possible.
      • Detail about Coroutine : https://twitter.com/ufcpp/status/703933114427379712
      • Detail about Why Task not coroutine : https://twitter.com/ufcpp/status/703934698435686400
  • [x] Sprite - Sorting Layer
    • Tutorial 3
    • As there are Bullet overwrite Player object. This seems not natual, it's better draw Bullet first and orverwrite with Player Object.
    • Use Sorting Layer to control draw Sprite object order.
    • Means Last Order Item will come to the top, tand first order item will be behind the last.
    • [x] Create Sorting Layer
      • Edit > Project Settings > Tags and Layer then select Sorting Layer Add 2 layers with this order.
        1. Bullet
        2. Player
    • [x] Apply to Sprite.
      • Set Player Sprite's Sorting Layer to Player
      • Set Bullet Sprite's sorting layer to Bullet.
  • [x] RequiredComponent Attribute
    • There are several Attributes in Script.
    • RequiredComponent Attribute means You must apply to the GameObject that Script Attached.
  • [x] Call other Script
    • Tutorial 4
    • You can call other class/method/property which assigned to same GameObject by GetComponent.
    • Create some common script A.
    • Attach script to GameObject X.
    • Now other Script, which also attach to GameObject X, can call Script through GetComponent().
  • [x] Transform.up
    • Usually direction is calculated from World Point, there are another easy way "Transform.up".
  • [x] Transform Rotation
    • In 2D, usually object direction is up. But you can flip direction to down or any with GameObject > Transform > Rotation.
  • [x] Child Element GameObject
    • Create Empty Elemment under a GameObject. Now created is Child Element and affected by Parent GameObject.
    • This can be use for Component of Large GameObject, like 1 enemy have many ShotPoint.
  • [x] Collider
    • Tutorial 5
    • Unity - Collier
    • UnityのRigidbodyとColliderで衝突判定
      • Would be better Collier and RigidBody are pair to set into Component.
      • When you add Collier, think like below.
      • If you Check on IsTrigger, Collider will not reflect material and passthru. It means DroppingObject will go through the Ground.
      • IsTrigger is useful for triggering any event when Item is touched.
    • [x] Add Collider
      • [x] Add Box Collider 2D to Player.
        • [x] Set size to 0.06 x 0.06
      • [x] Add Polygon Collider to Enemy
        • [x] Modify Mesh for Polygon Collider is not match to the Sprite shape.
          • Open Sprite and Change Texture Type to Advanced
          • Change MeshType
          • Change Extrude Edges
        • [x] Also modify Polygon Collider directly.
      • [x] Add Circle Collider to Enemy Bullet.
      • [x] Add Polygon Collider to Player Bullet.
        • [x] Copy / Paste Component
    • [x] Add Explosion Effect inside SpaceShipController
      • Instantiate Explosion GameObject at caller gameobject transform.
    • [x] Add OnTriggerEnter2D(Collider2D other)
      • Detroy(other.gameObject)
      • call Explosion effect
      • Destroy(self)
    • [x] Handle lopp for Explosion effect.
      • Change Loop setting in Animation
      • No Loop Time means run effect only once.
    • [x] Remove Animation Effect
      • [x] Destroy Explosion gameObject when OnAnimationFinish() event called.
      • [x] Link OnAnimationFinish Event to Animation
        • Open Animation. Windows > Animation
        • Add Event > Select OnAnimationFinish function
        • Move event to when Animation Finished
    • [x] Create GameArea
      • [x] Set OnColliderExit2D(Collider collider) to destroy collider when gameobject passed GameArea.
Component Dropping Object Catch Ground
Collider O (Shape to material) O (Shape to Ground)
RigidBody O (With Gravity) X
  • [ ] Layer
    • Tutorial 5
    • Easiest way to handle Collider is Splitting layer.
      • In this game I need to handle following combination will NOT destloy gameobject.
        • Player Bullet - Player
        • Enemy Bullet - Enemy
        • Player Bullet - Player Bullet
        • Enemy Bullet - Enemy Bullet
        • Player - Player
        • Enemy - Enemy
    • [x] Add Layer Edit > Project Settings > Tags and Layers
      • Player
      • Enemy
      • Bullet(Player)
      • Bullet(Enemy)
      • GameArea
    • [x] Apply Layer to Prefab and GameObject.
    • [x] Create Layer collistion Matrix. Edit > Project Settings > Physics 2D
      • You can hadle Layer collision with this matrix.
    • [x] Detail Handling with Script.
      • Even you set Layer Collision, Player still desloy right after game start. This is because GameArea Collision is affecting Players OnColliectionEnter2D.
      • Let's think this situation.
        • GameArea should be area to handle GameObject. Means It SHOULD DESTLOY GAMEOBJECT WHEN GAMEOBJECT is OnTriggerEnter2D.
        • This can't be handle with Layer Collision Matrix and required Script handling.
      • [x] Get Layer LayerMask.LayerToName(collider.gameObject.layer);
      • [x] If check for LayerName.... By String!?
      • [x] Destroy
  • [x] BackGround
    • Tutorial 6
    • [x] Quad
      • [x] Create Empty GameObject
      • [x] Create 3D > Quad inside GameObject.
      • [x] Attach BackGround Material
        • If you have several background meterials, then create multiple quad and apply each.
      • [x] Tune Z position for Visualize order.
        • larger amount will go back from smaller amount.
        • 0 will come front of 0.1
    • [x] Move Material
      • Use SetTextureOffset to move matrieal.
      • [x] Confirm Material's Shader Texture Varialbe Name
        • Unity basic shader often use _MainTex
        • You can confirm name with Select Matrial > Edit Shader > Compile and Show code ow Properties will show _MainTex or other.
      • [x] Change Texture Wrap Mode to Repeat
      • [x] Change TextureOffSet to move material
        • As Sprite don't have Offset, you need to use Material for controlling move by OffSet.
        • Get OffSet from time can be like this var y = Mathf.Repeat(Time.time * ScrollSpeed, 1); then var offset = new Vector2(0, y);
        • Move material by SetTectureOffSet() like this GetComponent<Renderer>().sharedMaterial.SetTextureOffset("_MainTex", offset);
      • About _MainTex : http://momijisoft.seesaa.net/article/430396670.html
      • Abount Graphoics.Blit : http://docs.unity3d.com/ja/current/ScriptReference/Graphics.Blit.html
  • [x] Wave
    • Tutorial 7
    • Wave, the pattern of how enemy show repeatedly.
    • Make Enemy wave and create it's prefab from Script.
    • [x] Create Wave Prefab
      • [x] Create empty GameObject as EnemyWave
      • [x] Copy Enemy Instantiated GameObject and position
      • [x] Assing Enemy GmaeObjects to EnemyWave
      • [x] Create EnemyWave Prefab
    • [x] Instantiate Wave Prefab from Script
  • [x] BGM
    • Tutorial 8
    • BGM can sound by attaaching to Camera
      • 3D Sound will consider distance of the Sounded object, means far item will be small volume.
      • 2D Sound will never consider distance of the Sounded object, means always same volume.
    • Attach BGM to the Camera and enable Loop
  • [x] SE
    • Tutorial 8
    • SE can be assign with Audio Source component.
      • [x] Call Play from Script. GetComponent<AudioSource>().Play();
  • [x] View port
    • Tutorial 9
    • Unity - Camera
    • View Port is "Area where Camera will view".
    • View Port will be range of 0,0 (left buttom)-> 1,1 (right top)
  • [x] Abstract Class
    • Tutorial 10
    • SpaceShipController can be Abstract class. PlayerController and EnemyController will derive from base class.
    • As Unity not accept Abstract class to be attach, common public Field can be inside Abstract class.
  • [x] Script Execution Order
    • Tutorial 10
      • There are Script Execution Order to manage script running order.
  • [x] Animator
    • Tutorial 10
    • [x] Create New Animator Layer Project Browser -> Animator
      • Dummy
      • Invincle
    • [x] Make Transition for Animation Layer
      • As name is Transition, it means how Animator move from/to.
      • In this case, Invincle is required for 3 seconds right after game start.
      • So the transition will be Invincle -> Dummy
  • [x] Animation
    • [x] Create new Animation in the Project Browser.
    • [x] Open Animation with Window > Animation
    • [x] Change to Invincle
    • [x] Add Box Collider 2D.Enabled
      • This means Collider Detection will be controllable with Animation.
      • If enable Key is removed to certain seconds, Attached GameObject will not detect.
    • [x] Add SpriteRenderer.Enabled
      • This means Sprite Rendering can be loop ON -> OFF.
      • Like Blinking!

Todo

Disclaimer

  • Visual Studio Tools for Unity 2.2 couldn't work with Unity 5.4.