UNITY | PROJECT | 2D PlatFormer | 2. Camera & Death

2
“CameraSystem” Script
  • Create Variables for Player, and Camera’s Scope
  • in Start() method,
    • find player by using FindGameObjectwithTag()

 

3
“Main Camera”
4
“CameraSystem” Script
  • in LateUpdate() method,
    • create x & y variable for the position of Main Camera
      • Put the x & y values of Player in those x & y
      • Clamp the x & y with min & max values
        • Main Camera will move based on Player‘s Position
        • when Main Camera reaches at the position of Min or Max Values, Main Camera stops there
4-1
Main Camera following but clamped

 

5
Adding Box with Box Collider

 

6
Adding Ground2 with Box Collider
6-1
“Box”

 

2. Camera - Death
Creating “Hole” with “Box Collider”
8
Creating and Adding “PlayerHealth” Script

 

9
“PlayerHealth” Script
  • Create died bool variable as Flag
  • in Start() method,
    • Set the Flag as false
  • in Update() method,
    •  if Player‘s y position is below than -7,(Player falls down), show the log

 

9-1
Player Falling
10
PlayerHealth Script
  • Create a Coroutine
    • Create Die() as IEnumerator
    • Start the Coroutine with Die() by putting StartCoroutine() in Update() when Player died
    • don’t forget to put yield and return in IEnumerator
10-1
CoRoutine Working
11
“PlayerHealth” Script
  • change IEnumerator Die()
    • load the main scene when this IEnumerator is called by using SceneManager.LoadScene()
    • Don’t forget to yield return null
12
Scene Loaded well

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |12. Spwan Waves

2
instantiating “hazard” inside “for loop” 

 

3
setting public variable “hazard count”

 

ezgif.com-video-to-gif
multiple “hazard”s are instantiated at the same time

 

 

4
using “WaitForSeconds()” to put a pause between every instantiation
5
creating “coroutine” to use “WaitForSeconds()”
6
setting “Game Controller” using “coroutine”

 

ezgif.com-video-to-gif-2
spawning “a” wave

 

7
adding “while loop” to make in

 

ezgif.com-video-to-gif-3.gif
having multiple waves of hazard

 

8
clones of “explosion” animation resting in the game
9.png
using “Destroy()” with “lifeTime” variable to remove useless GameObjects
10
setting destroy timer by selecting multiple components

ezgif.com-video-to-gif-4.gif