Time for action – add facial explosions

Just as we did when our falling object hit the ground, we'll use the Instantiate command to make a copy of a Prefab appear in the game world. This time around, when we determine that the player has been hit in the face by a bomb, we'll instantiate the Explosion Prefab on top of his head.

  1. Add the following line to the top of the code:
    var lastX:float;
    var isMoving:boolean = false;
    var explosion:GameObject;
    
  2. Later on, in the conditional statement that determines when the player is hit by a bomb, add the Instantiate command:
    if(col.gameObject.CompareTag("bomb")) { // I got hit by a bomb! Instantiate(explosion, col.gameObject.transform.position,Quaternion.identity); } else if (col.gameObject..CompareTag("stein")) ...

Get Unity 4.x Game Development by Example Beginner's Guide 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.