Game Development Reference
In-Depth Information
This script needs a prefab to instantiate, in addition to a time delay to wait between death
and next spawn. The script starts by calling
SpawnPlayer()
, which instantiates the prefab
of the character and keeps an internal reference to it in
currentInstance.
This reference
is necessary to destroy the player when a life is lost. Therefore, there is a need to handle
OnLifeLost
message sent by
LivesManager
, which is done by
OnLifeLost()
function. This
function destroys the current instance, and then calls
SpawnPlayer()
with the delay
predefined in
spawnDelay
. The lost of last life is handled through
OnAllLivesLost()
function, which destroys
currentInstance
, but this time without calling
SpawnPlayer()
.