UNITY | PROJECT | RPG Tutorial | 15. Debugging, Damage Taking, & Game Over

2-0
“Scene01” Script
  • FadeIn has never been turned off since it’s activated
3-1
UI – Button not Working
  • FadeIn is located on Canvas, where UI button is
  • with FadeIn on, the Buttons are under FadeIn (since FadeIn’s opacity is 0, we can’t see them)
  • the Buttons can’t be touched
2-2
“Scene01Skip” Script
  • create a script to turn off FadeIn 
3-2
UI-Text not Showing Up
3-0
“ChestTrigger” Script
  • even though we set the second UI Text shrinks automatically as soon as we open the chest, before shrinking the second UI Text was not activated.
    • there was nothing to shrink
46-e1536253559115.png
“ChestTrigger” Script
  • in Update() method, the local scale of UI-Text will be turned off when the localScale.y is less than 0
    • however, localScale is only set in Update() method.
    • there is no chance to access the localScale’s premier value
      • in Start() method,
        • set the localScale of UI-Text for Unity to access the value
5-1
UI-Working
5
“SpiderEnemy” Script
  • add SpiderAI as a component in the script
  • make spiderStatus variable as global by using static variable
  • spiderStatus = 0, means the spider is dead
    • when spider is dead, disable spiderAI script attached to Spider

setActive() vs enabled

setActive() turns off the gameObject

enabled turns off a component in the gameObject

6-1
Script Disabled
6
“SpiderAI” Script
  • create an int variable as an indicator for spider’s attacking
  • with another indicator, attackTrigger 1,
    • spider stops and the attack animation is player
    • IEnumerator TakingDamage() is played
  • create IEnumerator TakingDamage()
    • when an attack is done, set the indicator, dealDamage is set to 2
    • unless spider is dead,
      • Player’s health is taken by 1
    • wait for 0.5 sec
7
“HealthMonitor” Script
  • make this script reasonalbe
    • when Player has only one heart, turn off the second and third ones
    • when Player has two hearts, turn off the third one
8
GameOver Scene
9
GameOver Scene
  • create another scene, GameOver
  • add UI – RawImage for the black scren
  • add UI – Text for GameOver text
10
Build Setting
11
Build Setting
  • in Build Setting
    • add the first scene and the game over scene
    • pay attention to the scene numbers
2-1
“HealthMonitor” Script
  • when Player’s health  is 0, load the game over scene
13-1
Game Over Working