UNITY | Project | RPG Tutorial | 21. Complete Quest

2
“NPC001” Script
  • add gateTrigger to allow player to open the gate when he has received his this quest
3
updating Script
4
“GateOpen” Script
  • add Spider and Spider Boss to activate them after the door is open
5
Turning off Enemies
  • turn off as default
7
“SpiderBoss” Script
  • when Player kills the boss, Update the Quest Manager to proceed to the next Quest
8
Adding Component
  • duplicate NPC001 and make it as NPC001_complete
    • which has different saying
    • activated when the boss is killed
9
Duplicating Script
10
“NPC001_complete” Script
  • modify the condition and NPC’s saying
11
Adding Script

 

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 | 18. MiniMap Debugging, NPC Walking, & Saving Gold

2
“Quest001” Script
  • add a line of code to turn off MiniMap off when approaching enough
3
Updating Script

 

4-2
MiniMap Turned On
4
Updating ButtonManager
5
Adding NPC | Setting Default Animation
6
Measuring Vector3 with Cube
7
“NecromancerWalkAI” Script
  • create variables for
    • x, z position
    • where NPC head
  • in Start() method,
    • set X, Z values with Random.Range()
    • set the NPC’s transform.Position with a Vector3 with the X, and Z values
    • Start the Coroutine
  • in Update() method
    • make NPC keep looking at Cube(Destination) by using LookAt()
    • make NPC walk towards Cube(Destination) by using MoveTowards()
  • create IEnumerator RandomWalk()
    • wait for 5 seconds whenever creating changing the location of Cube(Destination) 
    • set X, Z values which we measured with Cube(Destination)
    • change the Cube(Destination)
    • get the Coroutine started in the Coroutine
      • automatically the Coroutine will be repeated

the logic is, make NPC  play “walk” animation, create a gameObject where NPC keep chasing, and make NPC walk towards it

8-1
NPC Walking

 

87.png
Adding Script
97.png
Creating RenderTexture for NPC Face
10
Adding Camera for NPC Face
116.png
Adding RenderTexture to Camera as Target Texture
124.png
Adding Render Texture to UI – RawImage
12-1
NPC Face Working

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

UNITY | PROJECT | RPG Tutorial |13. NPC

2
Adding NPC
3
NPC Idling
3
Adding collider
4
Adding “Text Box” from UI – Panel
  • set the anchor into stretch
5
Adding UI – Text for NPC Name
6
Adding UI – Text for NPC Saying
7
Adding UI-Raw Image for NPC Picture
8
Turning off TextBox
93-e1536078456298.png
“NPC001” Script
  • in Update() method,
    • put the Raycasting to get the distance from NPC to Player
  • in OnMouseOver() method,
    • if the distance between NPC and Player,
      • set the status of Player’s Sword into 1, unable to attack
      • show the message through UI Text
      • if Action Button is pressed,
        • set the status of Player’s Sword into 2, unable to attack
        • show Mouse Cursor
        • turn off the first UI Texts
        • get the Coroutine started
  • in IEnumerator NPC001Active()
    • show Text UIs for NPC talking
    • wait for 5 sec
    • turn off the UIs for NPC talking
    • show the first UI Texts
  • in OnMouseExit(),
    • set the status of Player’s Sword into 0, able to attack
    • turn off the first UI texts

 

10
Adding Script | Adding Components
11-1
Interacting with NPC