Our BeetleNPC script already detects collisions with the Cucumber Man, so we can simply update that script to deduct a point from the Cucumber Man's health when a collision is detected. We will do this by making a call to the ReduceHealth() method of the HealthManager script. Here are the steps:
- In the Project panel, select Assets | Custom Scripts and double-click the BeetleNPC script.
- Add the following statement in the class variables section of the script. This creates a variable we can use to reference the HealthManager class:
public HealthManager _healthManager;
- Add the following two statements in the OnCollisionEnter() method after the first if statement:
_healthManager = GameObject.Find ("Health_Slider")