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.
Add the following line to the top of the code:
var lastX:float; var isMoving:boolean = false; var explosion:GameObject;
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")) {
Save the Script.
In the Project panel, select the Character Prefab.
In the Inspector panel, locate the Explosion variable in the Script component.
Click-and-drag the Explosion Prefab into the Explosion variable slot.