Today I tried to make my player’s health work but I got an error and didn’t have time to solve this problem. I will try to solve this problem and show you how I solved it in the next post.
In the Enemy script, create an int variable called enemy_attack equals 10. I use this variable for minus player’s health when they touch each other.
Enemy Script
And in the Player script, create an int variable called player_health equals 100 and an enemy object variable. Then write a function that if an object is collided with Player is Enemy, minus player’s health with enemy_attack and print the player health.
Player Script
In the Inspector, move the Enemy into the Enemy of Player. It is helps the Player script can find the enemy_attack in Enemy script.
Inspector
But when I run the game it gave an error “Enemy is not defined” in console.
Console
No Responses