Currently, when our Cucumber Man collides with a Cucumber Beetle, the Die animation is played, but no other behaviors are implemented. In this section, we will modify the necessary scripts for the following to occur each time the Cucumber Man collides with a Cucumber Beetle:
- Beetle faces Cucumber Man
- Beetle attacks Cucumber Man for specified time
- Beetle's die animation plays
- Beetle is removed from game
We will use the following three lines of code inside our OnCollisionEnter() method to force the beetle to face the Cucumber Man when there is a collision. As you can see from the following code, we create a variable to make it easy to reference the Cucumber Man and then a second variable for the Cucumber ...