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 | SPACE SHOOTER 2D | 4. Enemy Animation & Enemy Spawner

2
Creating Enemy Animation
  • by selecting multiple Sprites and adding them in the scene, Create “EnemyAnimation”

 

3
Changing the name of EnemyAnimationController

 

4.1
“Enemy” GameObject

 

4.2
“Enemy” GameObject with Animation

 

5
Adding “EnemyControl” Script to “Enemy” GameObject

 

6.1
“EnemyControl” Script
  • Set the speed of Enemy with a float variable “speed”
  • in “Update()” method
    • change the position of “enemy” GameObject with “transform.position” every frame
    • for memory usage, destroy “enemy” when it goes out of the screen

 

6.2
“Enemy” Moving

 

6.3
“Enemy” Destroyed when outside of the screen

 

7
Creating “Enemy” Prefab

 

8
Creating “EnemySpawner” & Adding “EnemySpawner” Script
  • Create Empty GameObject and change its name into “EnemySpawner”
  • Create “EnemySpawner” Script and add it to “EnemySpawner”

 

9.1
“EnemySpawner” Script
  • To use “Enemy Prefab” in the script as a component
    • add “Public GameObject” variable
    • Don’t forget to add the reference in the inspector
  • Create a custom Function, SpawnEnemy()
    • Instantiate()
    • after instantiating, set the position of Enemy in a random position by using random range of “x” value
  • To make it spawn in 5 seconds

 

9.2
Enemy Spawning

 

10
Don’t forget to add the reference

 

11.1
“EnemySpawner” Script
  • Create a function, “ScheduleNextEnemySpawn()” to spawn multiple times
    • by using, “Invoke()” and putting “ScheduleNextEnemySpawn()” inside “SpawnEnemy()”
      • without using “loop”, we can make enemy spawned continuously
  • To increase the difficulty of the game, Create a function, “IncreaseSpawnRate()”

 

11.2
Spawning Enemies

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |11. Game Controller

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |11. Game Controller

2
adding “Game Controller”

 

3
adding “GameController” Script

 

6
Instantiating “Asteroid” as “hazard” | deciding the location and rotation of instantiation

 

7
using a temporary prefab to get Transform values

 

8
putting the values in a public variable as a medium

 

9
instantiating GameObject in random locations by using Random.Range()

 

11
Quaternion.identity, no rotating

 

ezgif.com-video-to-gif
Instantiating “hazard” 1
ezgif.com-video-to-gif-2
Instantiating “hazard” 2