Beetle attacks player on the ground

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 ...

Get Getting Started with Unity 2018 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.