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 |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

UNITY | PROJECT | 2D PlatFormer | 4. Score System

2
“PlayerScore” Script
  • create timeLeft & playerScore
  • in Update() method,
    • make timeLeft pass by using Time.deltaTime
    • create an if statement
      • when the time reaches approximately 0, load the scene again
  • in Awake() method,
    • temporarily, set the time into 5
3
“Player” Inspector

 

3-1
Time is passing

 

4
Creating “EndLevel”
  • create EndLevel from empty gameObject
    • add Box Collider
      • check is Trigger to make it as Trigger Collider
    • add RigidBody2D
      • set Body Type as Static
        • to make the gameObject immovable
        • the least resource-intensive body type
        • only collides with Dynamic RigidBody2D
        • Having two Static RigidBody2Ds colldie is not supproted
5
“PlayerScore” Score
  • create a Function, CountScore(),
    • update playerScore by calculating with timeLeft
    • create OnTriggerEnter2D()
      • put CountScore() in to make it activated when collisions happen

 

5-1
End Level
6
Creating UI

 

7
“PlayerScore” script
  • create GameObject variables for UIs
  • in Update() method,
    • use text property in UIs by using GetComponent()

 

7-1
UI Working

UNITY | PROJECT | SPACE SHOOTER 2D | 7. Collision Detection

2
Creating Tags
  • Create the tags for each GameObject
3
Tagging
  • Tagging each GameObject with its own Tag

 

4
Adding Collider & RigidBody2D to “Player”
5
Adding Collider & RigidBody2D to “Enemy”
6
Adding Collider & RigidBody2D to “PlayerBullet”
7
Adding Collider & RigidBody2D to “EnemyBullet”
  • Add Collider & RigidBody2D to each GameObject
    • Set “Is Trigger” in Collider to make it as “Trigger Collider”
    • SetGravity Scale in RigidBody2D to make them not to be affected by Gravity
    • Set “Freeze Rotation” in RigidBody2D to make them not spin when collided
8
OnTriggerEnter2D() | “PlayerControl” Script
9
OnTriggerEnter2D() | “EnemyControl” Script
10
OnTriggerEnter2D() | “PlayerBullet” Script
11.1
OnTriggerEnter2D() | “EnemyBullet” Script
  • Add “OnTriggerEnter2D(Collider2D)” method to each GameObject to detect and activate “Destroy()”
  • To Sort each Collision, Use “Collider2D.tag”

 

11.2

11.3
Collision Detection Working Well

13

125-e1531723319199.png
“PlayExplosion()” | “PlayerControl” Script
14.1
“PlayExplosion()” | “EnemyControl” Script
  • To Destroy “Player” or “Enemy”
    • Create a Function, “PlayExplosion()”
      • Instantiate the Explosion(Don’t forget to use “this.”)
    • Write the Function inside “TriggerEnter2D()” to make the instantiation of Explosion happen when a collision is detected
14.2
Explosion Animation & Collision Detection