Using Invoke to delay the execution of an explosion
In the previous recipe, we wanted to immediately instantiate and play a Particle System as soon as the player’s character collided with a crystal GameObject. However, there are times when we want to delay for a few moments when we want a prefab to be instantiated. This recipe customizes the previous one, in that we’ll allow our player to move around the scene while dropping bombs. Three seconds after being dropped, that bomb will be replaced by an explosion – an instantiation of our explosion Particle System from the previous recipe. This recipe is inspired, although in a much-simplified form, by games such as BomberMan.
Figure 15.30: Our Unity BomberMan
Getting ready
This recipe follows on from the previous one, so make a copy of that and work on the copy.
How to do it...
To delay an explosion using the Invoke(...)
method, follow these steps:
- Open a copy of the previous recipe...