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 | 6. Explosion​ Animation

2
Explosion Sprite | Sprite Editor

 

4
Explosion Sprite | Sprite Editor | Slice

 

5
Explosion Sprite | Inspector
  • For the Sprite of Explosion in the Inspector
    • Set the Sprite Mode into “Multiple”
    • Set the Filter Mode into “Point(no filter)”
    • Set the Max Sie into “1024”
6
Creating Animation from Sprite

 

7
“ExplosionAnimationContoller”
8
“Explosion” GameObject

 

9.1
Deselect “Loop Time”

 

9.2
“Explosion” Animation
  • “Explosion” Animation is appearing continuously

 

 

9.3
“Explosion” Animation

 

  • “Explosion” Animation works well except that the last frame of the animation lasts in the scene

 

10
Creating & Adding “Destroyer” Script

 

11
“Destroyer” Script
12
“Animation” Tap
13
Adding an Animation Event to “Explosion” Animation

 

14.1
Adding an Animation Event to “Explosion” Animation
14.2
“Explosion” Animation
15
Creating “Explosion” Prefab

UNITY | PROJECT | SPACE SHOOTER 2D | 3. Player Bullet and Player Shooting

SPACE SHOOTER 2D

3. Player Bullet and Player Shooting

3
Bullet Sprites
  • Importing “Bullets” sprite

 

5
Sprite Editor | Slice

 

  • by using “Sprite Editor”, slice “Bullets” sprites into 2 sprites
    • when slicing, set the type into “Grid By Cell Size”
    • when slicing, set the Pixel Size as 24×24

 

4

  • Having 2 bullet sprites

 

6
Sprite Setting
  • for the bullet sprite in the inspector
    • deselect “Generate Physics Shape”
    • Filter Mode into “Point(no filter)”
    • Max Size into “1024”

 

7
Adding prefab in the scene
  • Add “Player Bullet” sprite in the scene to configure like adding a script

 

8
Adding a script to Bullet GameObject
  • Adding “PlayerBullet” script to “PlayerBullet” GameObject

 

9
“PlayerBullet” Script
  • set the public variable “speed” for the speed of the bullet
  • In “Update()” method
    • get the bullet’s current position by using “transform.position”
    • computing the bullet’s new position = the change of position when we shoot the bullet
      • only need to change the “y” value
    • to smooth the shooting, use “Time.deltaTime”
    • Don’t forget to update the position into “transform.position”
  • for the memory usage, destroy the bullets going outside the screen
    • when setting the screen range, only consider “y” value or “height”
    • “Camera.main.ViewPortToWorlPoint()”

 

10
Setting the speed in the inspector | Public Variable
ezgif.com-video-to-gif
Shoot a bullet

 

11
Making a Prefab
  • Make the Bullet Prefab by dragging the bullet we configured in the Hierarchy window
    • this is the Bullet we will continuously instantiate

 

12
Empty GameObject

 

13
GameObject BulletPosition
14
GameObject BulletPosition
  • Make 2 Empty GameObject to Create “BulletPosition”, where Bullets come out
    • Set the position of  “BulletPosition” on “Player” GameObject

 

15
Child Object
  • Make “BulletPosition” as a ChildObject of “Player”
    • “BulletPosition” belongs to “Player”

 

16
“Player Control
  • Set Public Variables to use those components in the script

 

17
Public Variable | Reference

 

18
Player Control
  • In “Update()” method
    • Instantiate Bullet Prefab when “SpcaeBar” is pressed
    • set the initial position of a bullet after instantiating

 

ezgif.com-video-to-gif-2
Player Shooting | Destroying Bullets

 

UNITY | PROJECT | SPACE SHOOTER 2D | 1. CREATING PROJECT & PLAYER ANIMATION

SPACE SHOOTER 2D

1. CREATING PROJECT & PLAYER ANIMATION

2
Creating Project & Folders
  • creating the Project
  • creating Folders for each component
    • Scenes
    • Scripts
    • Prefabs
    • Sprites
    • Sound
    • Animations
3
Camera & BackGround
  • Changing BackGround Color
  • Changing Camera Size

 

4
Player Sprite | Sprite Editor
  • Adding “Player” Sprite to “Sprites” folder
  • Changing “Texture Type” to “Sprite(2D and UI)”
  • “Sprite Editor”

 

6
Sprite Editor
  • In “Sprite Editor”
    • changing Type to “Grid By Cell Type”
    • Pixel Size into X:72 / Y : 72
    • Press “Slice”

 

8
Sliced Sprite | Sprite Setting
  • “SpaceShip.png” has been sliced into 12 pieces
  • in the Inspector
    • deselect “Generate Mip Maps”
    • change “Filter mode” into “Point(no filter)”
    • change “Max Size” into 1024

 

9
Selecting multiple Sprites to create “Player” object
  • Trying to create “Player” object with animation by selecting multiple Sprites

 

10
Creating “Player” object with multiple Sprites
  • Saving “PlayerAnimation” in “Animation” folder
11
“Player” object with Animation
  • an “AnimationController” has been created automatically for “PlayerAnimation”

 

12
“PlayerAnimation”
13
Changing “Player” to “PlayerGo”

 

ezgif.com-video-to-gif
“PlayerGo” with animation