UNITY | Project | RPG Tutorial | 19. NavMesh & Boss AI

2
“NPC001” Script
  • when Player finishes the first Quest, change the saying of NPC by changing QuestNumber in QuestManager
3
Adding Trigger for Gate
  • Adding Cube for Trigger for opening Gate
4
“Quest002Start”
  • creating variables
    • for distance between Player and NPC
    • UI – Buttons
  • in Update() method,
    • getting the distance by using PlayerCasting
  • in OnMouseOver() method,
    • if Player is close enough to NPC
      • prevent Player from attacking
      • set the UI Text with messeges for Gate
      • if Action Button pressed
        • allow Player to attack
        • allow Player to use
        • turn off UI Text
ezgif.com-optimize.gif
NPC saying Different
5
Adding Cube as Walkable Ground
  • add Cube as a boundary for the boss to walk
6
Windows – AI – Navigation
7
Navigation | Walkable
8
Naviagtion | Bake
9
Turning off Mesh Renderer
10
NavMesh Agent
11
“SpiderBossAI”
  • create variables
    • where spider boss goes
    • NavMeshAgent
  • in Start() method,
    • make the NavMeshAgent variable NavMeshAgent
  • in Update() method,
    • through the NavMeshAgent variable, set where the boss to go
12
Adding Script
13
Animation
14
Animation | WrapMode
15
Creating Barriers
16
Barriers | Navigation | Non Walakble
17
Barriers | Bake | Bake
  • to prevent the boss from walking through the barriers, bake the barriers Non Walkable
18
SpiderBoss | NavMesh Agent | Radious like Collider
18-1
SpiderBoss Moving
19
Adding Cube as Trigger
  • put Spider Boss in a Cube Object named SpiderBossTrigger as child object
18-2
SpiderBoss Following Player
20
Adding Attack Animation
21
“SpiderBossAttack” Script
  • create variables
    • spider boss itself
    • as flag for attacking
  • in Update() method,
    • if attackTrigger is 0
      • make the boss walk with the animation
    • if attackTrigger is 0
      • if dealDamage  is 0
        • get the boss attack by player the animation
        • get the coroutine TakingDamage started
  • create IEnumerator TakingDamage()
    • set dealDamage into 2
    • wait for 1.1 sec
    • if spider’s status is not dead
      • get rid of one heart of Player
    • wait for 0.5 sec
    • set dealDamage into 0
  • in OnTriggerEnter() method,
    • when the boss touches Player, set attackTrigger into 1
  • in OnTriggerExit() method,
    • when Player gets out of the boss, set attackTrigger into 0
22
Adding Script
  • Adding Script
  • put SpiderBoss in the script
22-1
Spider Boss Following & Attacking Player

UNITY | PROJECT | RPG Tutorial |9. Weapon Animation

2
Creating Animation for Sword
316.png
Creating Animation for Sword
4
Creating Animation for Sword
  • create an Animation
    • by changing Transform(Position & Rotation) however I want
    • for each frame we can add changes
4-1
Creating Animation for Sword

 

5
“Animation” Component
  • Remove Animator(New)
  • Add Animation(Legacy)
    • Put the Animation for Sword in Animation Component as Animation & Element0
    • Since we have one animation, Set Size into 1
6
“Animation” | Legacy
  • in Animation Component,
    • in Debug tap, check Legacy
7
Animation | Wrap Mode | Once
  • to make Animation play once, change Wrap Mode into Once
8
InputManager | Key “Fire1” for Left Mouse Button
9
“SwingSword” Script
  • create Variables
    • for Sword we are yielding
    • for the status of sword
10-1
Animation Working
10
Adding Script to Sword
11
“AttackBlocker” Script
  • create a script to prevent Player from Yielding Sword in specific conditions
  • create variables one static and the other as path
  • in Update() method
    • put the static variable in the path variable
12
Adding “AttackBlocker” into “GlobalStat”
13
“Quest001” Script
  • add AttackBlocker.blockSword to Quest001 to change the status of swinging Sword
    • in OnMouseExit() method,
      • set the status as 0, indicating Swinging is available
    • in OnMouseOver() method,
      • when Action Button is pressed,
        • set the status as 2(actually 1), indicating Swinging is not available when grabbing the Notice
      • when Distance is less than 3,
        • set the status as 2(actually 1), indicating Swinging is not available when standing in front of the Notice Board
14
“SwingSword” Script
  • Add AttackBlocker.blockSword ==0 to the condition of if statement
14-1
Swinging Sword is not working

 

UNITY | PROJECT | RPG Tutorial |8. Completing Quests

2
“QuestButton” Script
  • add GameObjects for indicating that we have taken the quest
  • set the GameObject off when the function, AcceptQuest() is activated
3-0
Adding Components to Script
3-1
Taking Quest
4
“QuestButton” Script
  • create a function, DeclineQuest()
  • make things not have happend
5-01.png
Setting Action for Button
5-1
Declining Quest
6
“GlobalEXP” Script
11
“GlobalEXP” Script
  • Be careful with the order of variables
    • we are going to show internalEXP variable, which is the path for currentEXP , static variable
    • so, put the static variable in the path variable

 

7
“GlobalEXP” GameObject
8
Creating Trigger
9
“QuestComplete” Script
  • Create Variables
  • in Update() method,
    • get the distance between the trigger and Player
  • in OnMouseOver() method,
    • when the distance is lower than a specific value,
      • turn on the UI
      • put the text in the UI
      • if Action button is pressed,
        • turn off the marker
        • add EXP by 100
        • turn off the UIs
        • turn off the Trigger
  • in OnMouseExit() method,
    • turn off the UIs
10-0
Adding Components in Script
10-1
Be Careful with the Component Structure
  • even though the marker is on from the first moment, with the fact that the marker belongs to a GameObject which is turned off, the marker is off automatically
  • move the maker outside of the object
12-0
QuestTrigger” Script
  • add variables for exMarker and Trigger
  • when retrieving the Sword from the chest, turn on the marker and trigger in the notice board
12-1
Declining Quest
12-2
Taking Quest
12-3
Retrieving Sword
12-4
Completing Quest

13

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