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