- Any GameObject can be a bullet, but the GameObject must have
Collider
andRigidBody
components attached to it. - Bullet prefabs must be present in the
Resources/Projectiles
folder. - Make sure you add the
HitEnemy.cs
script as a component to every bullet prefab. - Damage incurred by each bullet upon hitting enemy can be set up in the
bulletDamage
public variable ofHitEnemy.cs
.
- Any GameObject can be an enemy, but the GameObject must have
Collider
andRigidBody
components attached to it. - Make sure you add the
HealthManager.cs
script as a component to every enemy prefab. - Each enemy initially has health equal to 100. This value can be changed in the
health
public variable ofHealthManager.cs
script.
- Each bullet prefab by default has a
bulletDamage
value of 10. - Upon hitting the enemy, the enemy changes color for a brief period and its health decreases.
- Since the health default value for an enemy is 100, you need 10 bullets to kill the enemy.
- When the health of an enemy becomes 0 (or <0), the enemy disappears.
- Every bullet hitting an enemy also disappears.
Here is an example.
- The bullet simply disappears.
- Right Mouse Click or Air Tap: Shoot the bullet in the direction of camera gaze pointer.
- Left Mouse Click or Air Tap: Reload the magazine of bullets.
- The radial menu is activated only when the right palm is facing the player.
- The radial menu appears on the left side of the right palm.
- The user has an arsenal of 8 types of bullets (each with its own damage and speed characteristics, this needs to be updated).
- The user can choose a bullet type by pressing it like a button using his/her left hand.
- Upon pressing a button, the user gets audio feedback and the button is highlighted to indicate selection.
- Each bullet type has its own shot sound and hit sound (these will be 3D sounds, this needs to be updated).
Here is an example.
- Run the scene and wait for the spatial understanding walls to get loaded (walls will stop loading visually speaking).
- Make sure you are in the Game Window of Unity before pressing the buttons mentioned below.
- Press the 'C' button for creating navmesh objects and attaching them to each of the walls.
- Press the 'B' button to bake the navmesh on the walls and the floor.
- Press the 'L' button to create navmesh links between the walls and the floor.
- You are all set to use the scene now!
- Click on any location in the scene using the left mouse button and the hermit and spider will go to that point.
- If the point is not reachable, they will go to their nearest reachable points.
- The paths followed by the minions is shown in the scene using line renderers.
- Remember, the spider can walk on any surface but the hermit can only walk on the floor.
- For the spider and the hermit, you can toggle between follow player and don't follow player modes by checking/unchecking the follow player checkbox on the
Minion Follow Player Script
component of that particular object. - You can also shoot at the minions to kill them. See the radial menu behaviour section above.
Here is an example.
- Every enemy is in Locomotion state at game start.
- To make use of activation/deactivation behaviour, set the
isBoss
bool onHealthManager
component of the respective enemy totrue
by checking the box. - Then, set the value of the
Resurrection Time
float onHealthManager
component. This is the time in seconds for which the boss is deactivated. - Also set the value of the
Recurrected Health Percentage
float. For example50
, which means 50%. - While the boss is deactivated, you can prevent certain actions such as navigation and shooting at the player by making use of the
Activate
bool parameter on theAnimator
component of the boss. Just check ifGetComponent<Animator>.getBool("Activate")
istrue
and only then should you execute these tasks. - The boss will automatically go back to activated state after his
Resurrection Time
is complete and his health will be restored toMAXHEALTH * (Resurrected Health Percentage) / 100
.
When the Boss is in deactivated state, we want to show a path along which the player can navigate Kuri to kill the boss. Here is the current implementation of this,
- You need to drag and drop the
Spider_Hvy
object (or whatever the boss object is) into theBoss
variable ofComputePathToBoss
component on Kuri. - The path is calculated and shown only when the
Boss
is in deactivated state. - A voice over may be added which says, "Navigate Kuri, along the path shown, to kill the boss!" (not yet implemented). A message can also be shown on the screen.
- The path is continuously redrawn according to the current position of Kuri.
- The path that was drawn disappears once the
Boss
is reactivated (before Kuri can kill it).
There are two ways to spawn minions. Either enable auto-spawning or use a manual function call.
Before we discuss both of these, you need to ensure that you have added the MinionSpawner
component on the boss object.
- In order to auto-spawn enemies, you need to edit the
MinionSpawner
script by setting thecoroutineRunning
variable in itsStart()
function tofalse
. This is not a public variable since this coroutine keeps running, so its status cannot be changed after the game has started. - You can edit the maximum number of enemies the boss will auto-spawn by changing the
autoNumberOfMinions
public variable ofMinionSpawner
. - You can also change the time between successive minion spawns by changing the
autoSpawnTime
public variable ofMinionSpawner
. This time should be in seconds. - Provided auto-spawning is enabled using point 1, the boss will keep spawning minions until the number of spawned minions that are alive reaches
autoNumberOfMinions
. If any of these minions dies, the boss will spawn another one ensuring that the previous statement is always true. - The minions are spawned in the forward direction of the camera and behind the boss i.e. an offset is added to the position of the boss in the direction of the camera gaze to determine where the minion should be spawned. This offset value is a public float called
forwardOffset
on theMinionSpawner
. - The spawned minions immediately start following the player.
- You can call the
SpawnMinion()
function ofMinionSpawner
to spawn a new minion. This function returns a reference to the newly created minion object. - The minion is spawned at the position mentioned in point 5 under Auto Spawning.
MinionSpawner
remembers the way a minion was spawned. So if you kill a minion that was spawned manually, the boss won't spawn a new minion to replace him. That behaviour is only exhibited by the minions spawned automatically.- The spawned minions immediately start following the player.
- At game start, the minions can only walk on the floor.
- NavMeshLinks are nothing but bridges to connect two surfaces. So to enable walking on walls, links are required between the walls and the floor. Similarly, to enable walking on the ceiling, links are required between the walls and the ceiling. Without the links, a minion on the floor cannot jump on a wall and a minion on a wall cannot jump on the ceiling.
- At runtime, you can change the walkable surfaces (for minions only) using the
enableWallFloorLinks
andenableWallCeilingLinks
public bools present on theCreateNavMeshesAndNavMeshLinks
component ofSceneUnderstanding -> Root
game object. - Enjoy!