O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required