UNITY | PROJECT | 2D PlatFormer | 4. Score System

2
“PlayerScore” Script
  • create timeLeft & playerScore
  • in Update() method,
    • make timeLeft pass by using Time.deltaTime
    • create an if statement
      • when the time reaches approximately 0, load the scene again
  • in Awake() method,
    • temporarily, set the time into 5
3
“Player” Inspector

 

3-1
Time is passing

 

4
Creating “EndLevel”
  • create EndLevel from empty gameObject
    • add Box Collider
      • check is Trigger to make it as Trigger Collider
    • add RigidBody2D
      • set Body Type as Static
        • to make the gameObject immovable
        • the least resource-intensive body type
        • only collides with Dynamic RigidBody2D
        • Having two Static RigidBody2Ds colldie is not supproted
5
“PlayerScore” Score
  • create a Function, CountScore(),
    • update playerScore by calculating with timeLeft
    • create OnTriggerEnter2D()
      • put CountScore() in to make it activated when collisions happen

 

5-1
End Level
6
Creating UI

 

7
“PlayerScore” script
  • create GameObject variables for UIs
  • in Update() method,
    • use text property in UIs by using GetComponent()

 

7-1
UI Working