UNITY | Project | RPG Tutorial | 20. Death Of Boss & Open Gate

2
Adding Animation for Death
3-1
NavMesh | Walking Boundary Working

 

3-2
Boss Working
3
“SpiderBoss” Script
  • create variables for
    • enemy health as 20 for boss
    • spider boss itself
    • flag for spider’s status
    • EXP when we kill the boss
    • EXP calculated relatively to Player’s level
    • spider’s AI
    • spider’s status
    • NPCs
    • flag for spider’s attack
  • in Start() method,
    • get the components of SpiderAI and SpiderAttack
  • create a function, DetuctPoint(),
    • when enemy is attacked, enemy’s health is decreased by the damageAmount
  • in Update() method,
    • make the spider’s status as global
    • if enemy’s health is less than 0
      • start the coroutine, DeathSpider
  • create IEnumerator DeathSpider(),
    • when spider is dead, disable the AI Script
    • set the spider’s status as 6
    • calculate the EXP
    • play the animation for death
    • turn on or off the NPCs

511.png

  • decrease the health of Spider Boss into 5 to make debugging faster
  • when Spider Boss died, turn off the Spider’s attack script

 

5-1
Boss died
6
“OpenGate” Script
  • create variables
    • distance between Player and Gate
    • UI Buttons
    • Gates themselves
  • in Update() method,
    • get the distance by using PlyerCasting Class
  • in OnMouseOver() method,
    • if the distance is less than 3
      • Player’s attack is blocked
      • showing the UI Buttons
      • if Action Button is pressed,
        • the collider attached to the gate is disabled
        • update Attack Blocking
        • UI Buttons disappear
        • play the Animations of opening Gate
7
Setting Gate by making hinge with Cube
8
Create Animation for Opening Door
910.png
Turning off Loop in Animation
10
Animation | Legacy
11
Adding Animation
127.png
Adding Script
12-1
Gate Opening

 

UNITY | PROJECT | RPG Tutorial |14. Enemy AI

2
“SpiderAI” Script
  • create a variable for Player
  • in Update() method,
    • make Spider keep looking at Player by using transform.Lookat()
3
Adding Script
4
“SpiderAI”
  • create variables for
    • Player
    • distance obtained by RayCasting
    • distance where Enemy starts to move towards Player
    • Spider itself
    • speed of Spider
    • attack trigger to indicate when spider starts to attack
    • for RayCasting
  • in Update() method,
    • put the information from RayCasting to the RayCastingHit variable
    • put the distance from RayCasting into the variable for distance
    • if Player is within the minimum range of Spider,
      • set the speed of Spider
      • if attackTrigger is 0,
        • make Spider move with the animation, “walk”, toward Player by setting its tranform
    • if Player has left from the range of Spider,
      • set the speed of Spider into 0
      • make Spider idlen with the animation, “idle”
5-1
AI Working : Walking
5
Adding Script
6
“SpiderAI” Script
  • in Update() method,
    • add another if statement,
      • if attackTrigger is 1
        • set the speed of Spider into 0
        • make spider attack with animation, “attack”
  • in OntriggerEnter() method,
    • when spider touches somthing(Player), set attackTrigger into 1
  • in OntriggerExit() method,
    • when Player has escaped Spider, set attackTrigger into 0 to make it stop attack
7-2
AI Working : Attacking
7
Adding Collider
  • add Mesh Collider to Player
    • Convex, and is Trigger