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

UNITY | PROJECT | RPG Tutorial |11. Enemy & Inflicting Damage

 

3

4
“InflictDamage” Script
  • create Variables
    • damageAmount for Damage Amount for this weapon
    • allowedRange for Reach of this weapon
  • in Update() method,
    • when Left Mouse Button is pressed,
      • create a RayCastHit variable
      • put the RayCast in the variable
      • when the Distance obtained by RayCasting(hit.distance) is lower than the Reach(allowedRange),
        • hit.transform is in this context, the enemy spider
        • Enemy spider has the function, DeductPoints
        • make the funtion attached to Enemy GameObject activated by using SendMessage activated
          • InflictDamage will send a message to SpiderEnemy and activate the function
        • since we don’t want to put a receiver for the message in the spider object, set the option, DontRequireReceiver
5
Creating Dummy for Enemy
6
Adding “InflictDamage” Script to Weapon
7
“SpiderEnemy”
  • create a variable for the Spider’s Health
  • create a function, DeductPoint with argument, int damageAmount
    • deduct the damage from the health when this function is activated
  • in Update() method,
    • if the health is below than 0,
      • get the coroutine started
  • create a IEnumerator, DeathSpider()
    • wait for 0.5 sec before destroying the gameObject
7-1
Inflicting Damage Working

UNITY | PROJECT | RPG Tutorial |5. RayCasting

2
Creating “PlayerCasting” script
3
“PlayerCasting” script
  • creating a static variable for the distance of RayCasting
    • create another variable as a internal path for the static variable
  • in Update() method,
    • imply a RayCasting from the mission board, with the direction of forward
    • with out keyword, put the information of RayCasting into hit variable
    • put the distance between the mission board and player in toTarget
    • connect the static variable and the path variable
3-1
RayCasting Working
4
Creating Text UI for indicating Key
5
Creating Text UI for indicating Action
6
InputManager | Adding a button
7
Adding a quest note with Plane
8
“Quest001” Script
  • creating Variables
  • in Update() method,
    • put the distance from the RayCasting in PlayerCasting Class  into “distance
      • for this, distanceFromTarget is set as Static
  • in OnMouseOver() method,
    • if the distance of RayCasting is less than 3,
      • set ActionButton and ActionText active
      • if Action button is pressed,
        • set actionButton, ActionText, and Player inactive
        • set UIQuest and Notice Camera active
  • in OnMouseExit() method,
    • set actionButton and actionText inactive
10
Adding RawImage UI | Making Notice UI for Quest
11
Setting Components off as default value
12
Notice Camera for the Quest
13
Making a Trigger with Cube
14
Making a Trigger with Cube
  • Be careful with the position of Triggers
  • If it’s buried in the other objects like the notice board, it is not detected by RayCasting
15
Put Components in the script
15-1
RayCasting Working
15-2
Action Working

UNITY | PROJECT | 2D PlatFormer | 6. Enemy

2
“PlayerControl” Script
  • with the rayCasting downwards, detect Enemy
    • Kill Enemy
      • enter Enemy‘s properties to modify gravityScale, FreezeRotation, BoxCollider2D, EnemyControl
2-1
Killing Enemy

 

3
“EnemyHealth” Script
  • when GameObject(=Enemy)’s position is lower than -10 in y
    • destroy Enemy

 

3-1
“Enemy” Destroyed

 

6. Enemy 1
“PlayerControl” Script
  • Crate another RayCast upwards
    • if detecting BoxSpecial, Destroy it

 

5
Creating “BoxSpecial”
  • add Box Collider 2D

 

5-1
Destroying Box