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 |7.Triggers ,Weapons & Objectives

2
Making Clearing in Woods
3
Creating Collider as Trigger
4
“QuestTrigger” Script
  • create variables
    • the objective to configure
    • the flag to indicate we finish the objective
    • scale for the Objective
  • in Update() method,
    •  make if statement
      • change the locale scale of UI Text
      • make it disappear when the scale is 0
5
Adding Chest
5-1
Opening the top of Chest
6
Creating Animation for the top of Chest
7
Creating Animation with Transform.Rotation
8
Creating Animation with Transform,Rotation
8-1
Animtation Working
bandicam 2018-08-28 20-55-18-493
Adding “Animation” Component
9
Changing Setting in Dubug | Selecting “Legacy”
  • Since Animation Component is old one, to use it, we need to check Legacy option checked
12
Deselecting “Play Automatically”
12-1
10
Adding “Box Collider” as “Trigger”
13
Adding “Box Collider”
  • add Box Collider to prevent Player coming into Chest
14
Adding “Chest Trigger” Script to Trigger Collider
15
“ChestTrigger” Script
  • create Variable
    • for RayCasting to get the distance between Player and this Object itself
    • for Chest
    • for UIs
    • as a Flag to check whether we finish the obective
  • in Update() method,
    • get the distance
    • if the distance is lower than a specific value,
      • lower the scale of UI
      • make it disapear
  • in OnMouseDown() method,
    • when Cursor is on the object, and the distance is lower than a specific vlaue,
      • put the text into UI
      • make UIs appear
      • if Action button is pressed,
        • turn off the Box Collider
        • Play the animation of Chest
        • set the flag
        • turn off UIs
16
Adding Trigger & “Sword Trigger” Script
17
“Sword Trigger” script
  • create Variable
    • for RayCasting to get the distance between Player and this Object itself
    • for Sword
    • for UIs
    • as a Flag to check whether we finish the obective
  • in Update() method,
    • get the distance
    • if the distance is lower than a specific value,
      • lower the scale of UI
      • make it disapear
  • in OnMouseDown() method,
    • when Cursor is on the object, and the distance is lower than a specific vlaue,
      • put the text into UI
      • make UIs appear
      • if Action button is pressed,
        • turn off the Box Collider
        • Play the animation of Chest
        • set the flag
        • turn off UIs
17-1
Retriving Sword

 

UNITY | PROJECT | 2D PlatFormer | 5. Collectables

2
Creating “Coin”
  • create Coin
    • add Circle Collider 2D
      • make it Trigger Collider by checking Is Trigger
    • add RigidBody2D
      • make it Static Collider

 

3
“PlayerControl” Script
  • in OnTriggerEnter2D() method,
    • if a collision with Coin happens
      • add score by 10
      • destroy the gameObject itself (=Coin)
    • OnTriggerEnter2D vs OnCollisionEnter2D
      • When there are TriggerColliders, use OnTriggerEnter2D
      • When there are normal Colliders, use OnCollisionEnter2D

 

3-1
Collecting Coin Working

 

4
ProjectSetting | Physics2Dsetting
  • Uncheck “Queries Start in Colliders”
    • I guess Query there means anything to detect in physics such as RayCast
    • with that option checked, RayCasting starts from the inside of collider attached to GameObjects
    • with that option unchecked, RayCasting Starts from the collider attached to GameObjects

 

5
“Enemy” Inspector
  • Tag as “Enemy”
  • Set the layer as “Default”

 

6
“PlayerControl” Script
  • create a function, PlayerRayCast(),
    • attach RayCast by using RayCastHit2D, and Physics2D.RayCast(vector2 origin, vector2 direction)
    • create an if statment,
      •  give Player jump by using GetComponent<RigidBody2D>.AddForce()

 

7
“PlayerControl” Script
  • Add PlayerRayCast() function in Update() method

 

7-1
Jumping on “Enemy”

 

8
Experiment | Layer : Ignore RayCast
  • put Enemy back in IgnoreRayCast Layer

 

8-1
RayCasting Not Working
  • with the option, “Queries Start in Colliders” unchecked, Enemy is moving correctly because RayCasting Starts from the exterior of Collider attacked to Enemy
  • with the fact that Enemy belongs to Ignore RayCast layer, the RayCasting feature is not working

 

9
“EnemyControl” Script
  • in Update() method,
    • with the Raycasting feature, Enemy detects other objects horizontally
    • in the horizon, if Enemy collides with Player, Destroy Player

 

9-1
Jumping on “Enemy”

 

10
“PlayerControl” Script
  • in PlayerRayCast(),
    • set if statements with the conditions,
      • if Player hit anything, and if it is Enemy, make Player jump on Enemy
      • if Player hit anything, and if it is not Enemy, set the flag for jump as true
10-1
“Player” can jump anywhere but “Enemy”

 

 

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 | 2D PlatFormer | 2. Camera & Death

2
“CameraSystem” Script
  • Create Variables for Player, and Camera’s Scope
  • in Start() method,
    • find player by using FindGameObjectwithTag()

 

3
“Main Camera”
4
“CameraSystem” Script
  • in LateUpdate() method,
    • create x & y variable for the position of Main Camera
      • Put the x & y values of Player in those x & y
      • Clamp the x & y with min & max values
        • Main Camera will move based on Player‘s Position
        • when Main Camera reaches at the position of Min or Max Values, Main Camera stops there
4-1
Main Camera following but clamped

 

5
Adding Box with Box Collider

 

6
Adding Ground2 with Box Collider
6-1
“Box”

 

2. Camera - Death
Creating “Hole” with “Box Collider”
8
Creating and Adding “PlayerHealth” Script

 

9
“PlayerHealth” Script
  • Create died bool variable as Flag
  • in Start() method,
    • Set the Flag as false
  • in Update() method,
    •  if Player‘s y position is below than -7,(Player falls down), show the log

 

9-1
Player Falling
10
PlayerHealth Script
  • Create a Coroutine
    • Create Die() as IEnumerator
    • Start the Coroutine with Die() by putting StartCoroutine() in Update() when Player died
    • don’t forget to put yield and return in IEnumerator
10-1
CoRoutine Working
11
“PlayerHealth” Script
  • change IEnumerator Die()
    • load the main scene when this IEnumerator is called by using SceneManager.LoadScene()
    • Don’t forget to yield return null
12
Scene Loaded well