UNITY | PROJECT | 2D PlatFormer | 1. Project Set Up

2
Importing Sprites

 

3
Cutting Sprites

 

4
Creating “Ground”
  • Add “Box Collider” to “Ground”

 

5
Adding “Player”
  • Add “Box Collider” to “Player”
  • Add “RigidBody2D” to “Player”
7.1
Adding “PlayerControl” Script
7.2
Physics Working

 

8
“PlayerControl” Script
  • Claim variable for Player movement
    • playerSpeed
    • facingRight as flag
    • playerJumpPower
    • movementX
  • in “Update()” method
    • get input to move horizontally by using “Input.GetAxis()”
    • get “RigidBody2D” component by using “GetComponent()”
      • call “velocity” propery to move “Player” with continuous input
    • create “if Statement” for Player’s movment
      • when pressing left and facing right
        • activate “FlipPlayer()” method
      • when pressing right and facing left
        • activate “FlipPlayer()” method
    • Create a Function, “FlipPlayer()”,
      • set the flag, “facingRight” to opposite
      • get the “localScale” property
        • multiply -1 to reverse the direction
      • Don’t forget to update “localScale”
10.2
Player Moving
9
“PlayerControl” Script
  • Create a function, “Jump()’,
    • use “AddForce()” to give force upwards to “Player”
  • in “PlayerMove()” method,
    • when “Jump” button is pressed, activate “Jump()” method

 

10.1
Input Manager

 

10.3
Player Jumping too high

 

11.1
RigidBody2D | Linear Drag | Gravity Scale
  • Set “Linear Drag” 0 to 1 to prevent “Player” from jumping too much
  • Set “Gravity Scale” 0 to 10 to prevent “Player” from jumping too much

 

11.2
Player Jumping
  • Player jumps normally but still it can jump multiple times in the air

UNITY | PROJECT | SPACE SHOOTER 2D | 7. Collision Detection

2
Creating Tags
  • Create the tags for each GameObject
3
Tagging
  • Tagging each GameObject with its own Tag

 

4
Adding Collider & RigidBody2D to “Player”
5
Adding Collider & RigidBody2D to “Enemy”
6
Adding Collider & RigidBody2D to “PlayerBullet”
7
Adding Collider & RigidBody2D to “EnemyBullet”
  • Add Collider & RigidBody2D to each GameObject
    • Set “Is Trigger” in Collider to make it as “Trigger Collider”
    • SetGravity Scale in RigidBody2D to make them not to be affected by Gravity
    • Set “Freeze Rotation” in RigidBody2D to make them not spin when collided
8
OnTriggerEnter2D() | “PlayerControl” Script
9
OnTriggerEnter2D() | “EnemyControl” Script
10
OnTriggerEnter2D() | “PlayerBullet” Script
11.1
OnTriggerEnter2D() | “EnemyBullet” Script
  • Add “OnTriggerEnter2D(Collider2D)” method to each GameObject to detect and activate “Destroy()”
  • To Sort each Collision, Use “Collider2D.tag”

 

11.2

11.3
Collision Detection Working Well

13

125-e1531723319199.png
“PlayExplosion()” | “PlayerControl” Script
14.1
“PlayExplosion()” | “EnemyControl” Script
  • To Destroy “Player” or “Enemy”
    • Create a Function, “PlayExplosion()”
      • Instantiate the Explosion(Don’t forget to use “this.”)
    • Write the Function inside “TriggerEnter2D()” to make the instantiation of Explosion happen when a collision is detected
14.2
Explosion Animation & Collision Detection