Skip to content

guitarrapc/UnityTutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Done

Roll-a-Ball

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

Additional

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

2D Shooting

  • Player Settings
    • Before started
    • Modify Player Resolution Settings
    • Edit > Project Preference > PlayerSettings > Resolution and Presentation
    • 600 x 400
  • Game View Resolution
  • Sprite
    • Tutorial 1
    • What is Sprite : http://docs.unity3d.com/ja/current/ScriptReference/Sprite.html
      • Spirite Object in 2D Game Play
    • Texture Type
      • Should set as Sprite
    • Sprite Mode
      • Multiple : If Texture contains more than one sprite
      • Single : If Texture contains only one sprite
    • 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
  • 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.
    • Open Sprite Editor from Inspector View
    • Select Slice on left top.
      • Type == Automatic means automatically slice Sprite.
      • Change Type to Grid by cell Size
      • Set Slice size in Pixcel size than run slice.
      • Apply to chang takes effects.
  • Animation
    • Tutorial 1
    • Create Animation
      • Drag and Drop > Select Folder name to be created.
    • Change Hierarchy GameObject Name to Player, change Animation name to Normal, Player.
    • Create Animations
      • Create Player
      • Create Enemy
      • Create Bullet (Only Sprite)
      • Create Explode
    • Create Prefab.
    • Set All Prefab Position to 0,0,0 (actually only x and y. z always 0 in 2D mode)
    • Remove Apply Root Motion for 2D.
      • It doesn't use in 2D and will be break what you desire.
  • Rigidbody2D
    • Tutorial 2
    • RigidBody for 2D
    • Set Gravity Scale to 0
    • Script to move Player
      • Add Component > C# Script
      • 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.
      • 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.
      • 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.
  • Camera
    • Tutorial 2
    • 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.
  • Add Bullet
    • Tutorial 3
    • Add RigitBody2D to the bullet.
    • Set Bullet position in SceneView and drag to container gameobject. (PlayerBullet)
    • Create Prefab for contaier object PlayerBullet.
    • 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;
  • 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
  • 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.
    • Create Sorting Layer
      • Edit > Project Settings > Tags and Layer then select Sorting Layer Add 2 layers with this order.
        1. Bullet
        2. Player
    • Apply to Sprite.
      • Set Player Sprite's Sorting Layer to Player
      • Set Bullet Sprite's sorting layer to Bullet.
  • RequiredComponent Attribute
    • There are several Attributes in Script.
    • RequiredComponent Attribute means You must apply to the GameObject that Script Attached.
  • 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().
  • Transform.up
    • Usually direction is calculated from World Point, there are another easy way "Transform.up".
  • Transform Rotation
    • In 2D, usually object direction is up. But you can flip direction to down or any with GameObject > Transform > Rotation.
  • 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.
  • 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.
    • Add Collider
      • Add Box Collider 2D to Player.
        • Set size to 0.06 x 0.06
      • Add Polygon Collider to Enemy
        • 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
        • Also modify Polygon Collider directly.
      • Add Circle Collider to Enemy Bullet.
      • Add Polygon Collider to Player Bullet.
        • Copy / Paste Component
    • Add Explosion Effect inside SpaceShipController
      • Instantiate Explosion GameObject at caller gameobject transform.
    • Add OnTriggerEnter2D(Collider2D other)
      • Detroy(other.gameObject)
      • call Explosion effect
      • Destroy(self)
    • Handle lopp for Explosion effect.
      • Change Loop setting in Animation
      • No Loop Time means run effect only once.
    • Remove Animation Effect
      • Destroy Explosion gameObject when OnAnimationFinish() event called.
      • Link OnAnimationFinish Event to Animation
        • Open Animation. Windows > Animation
        • Add Event > Select OnAnimationFinish function
        • Move event to when Animation Finished
    • Create GameArea
      • 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
    • Add Layer Edit > Project Settings > Tags and Layers
      • Player
      • Enemy
      • Bullet(Player)
      • Bullet(Enemy)
      • GameArea
    • Apply Layer to Prefab and GameObject.
    • Create Layer collistion Matrix. Edit > Project Settings > Physics 2D
      • You can hadle Layer collision with this matrix.
    • 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.
      • Get Layer LayerMask.LayerToName(collider.gameObject.layer);
      • If check for LayerName.... By String!?
      • Destroy
  • BackGround
    • Tutorial 6
    • Quad
      • Create Empty GameObject
      • Create 3D > Quad inside GameObject.
      • Attach BackGround Material
        • If you have several background meterials, then create multiple quad and apply each.
      • Tune Z position for Visualize order.
        • larger amount will go back from smaller amount.
        • 0 will come front of 0.1
    • Move Material
      • Use SetTextureOffset to move matrieal.
      • 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.
      • Change Texture Wrap Mode to Repeat
      • 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
  • Wave
    • Tutorial 7
    • Wave, the pattern of how enemy show repeatedly.
    • Make Enemy wave and create it's prefab from Script.
    • Create Wave Prefab
      • Create empty GameObject as EnemyWave
      • Copy Enemy Instantiated GameObject and position
      • Assing Enemy GmaeObjects to EnemyWave
      • Create EnemyWave Prefab
    • Instantiate Wave Prefab from Script
  • 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
  • SE
    • Tutorial 8
    • SE can be assign with Audio Source component.
      • Call Play from Script. GetComponent<AudioSource>().Play();
  • 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)
  • 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.
  • Script Execution Order
    • Tutorial 10
      • There are Script Execution Order to manage script running order.
  • Animator
    • Tutorial 10
    • Create New Animator Layer Project Browser -> Animator
      • Dummy
      • Invincle
    • 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
  • Animation
    • Create new Animation in the Project Browser.
    • Open Animation with Window > Animation
    • Change to Invincle
    • 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.
    • 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.