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 your existing collision detection code:
    var lastX:float;
    var isMoving:boolean = false;
    var explosion:GameObject;
    
  2. Later on, in the conditional statement, add the Instantiate command:
    if(col.gameObject.tag == "bomb")
    {
    // I got hit by a bomb!
    Instantiate(explosion, col.gameObject.transform.position, Quaternion.identity);
    }
    else if (col.gameObject.tag == "stein") {
    
  3. Save and close the Script.
  4. In the ...

Get Unity 3D Game Development by Example 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.