Gamespace: Enemies
I wanted to create an enemy that when the player collides with the object points are deducted from the health bar. I also wanted my enemy to fit with the theme and therefore made it look like a raincloud.
Raincloud enemy with added box collider |
Raincloud enemy deducting points from the health bar |
This is the inspector for the raincloud enemy.
The 'Enemy' script is attached and a box collider component is added so that when the player collides with the enemy the script understands that a collision has occurred.
The Enemy script works by using an 'OnTriggerEnter' function. Therefore, when the player collides with the box collider that encapsulates the rain and rain cloud this function is called.
Cloud Enemy Inspector |
The variable 'healthBar' is received.
If the value assigned to the health bar is not equal to nothing, then the health bar takes 10 damage when the player collides with a raincloud.
The emission and shape values were tweaked slightly but mostly stayed the same.
The collision was switched on so that if the rain particles collided with the ground, they wouldn't just fall through it.
Enemy Script |
To make my raincloud enemy more realistic, I added a particle system so it appeared that the cloud was raining.
The play on awake and looping options were checked as I wanted this particle system to be a continuous stream of particles to resemble rain.
Particle system for raincloud rain |
The emission and shape values were tweaked slightly but mostly stayed the same.
Emission & shape for the particle system |
The collision was switched on so that if the rain particles collided with the ground, they wouldn't just fall through it.
Comments