Graphics Reference
In-Depth Information
Finally, a call to the Respawn() function of this class is scheduled to happen 2 s from
now via Unity's Invoke() function:
// respawn
Invoke("Respawn",2f);
}
}
After the player has been destroyed by an enemy projectile, it is hidden from
view and its collisions ignored. The Respawn() function resets the player state back to
operational:
void Respawn()
{
By the end of this function call, the player will have respawned, which means
isRespawning is now to be set to false:
// reset the 'we are respawning' variable
isRespawning= false;
To prevent respawning the player into a dangerous place on screen (such as right into
the path of a projectile) and causing instant death upon respawn, the player is made invul-
nerable for a few seconds:
// we need to be invulnerable for a little while
MakeInvulnerable();
The player regains its susceptibility to explode upon projectile impact in 3 s time,
which is done with an Invoke call to MakeVulnerable():
Invoke ("MakeVulnerable",3);
The player's spaceship model is set active, effectively displaying it again, here:
// show ship body again
theMeshGO.SetActive(true);
Any power-ups are lost on respawn by setting the weapon slot back to the beginning.
If you wanted to keep power-ups even after a life is lost, you could comment this line out
or perhaps replace it with weaponControl.PrevWeaponSlot() to downgrade the weapon to
the previous slot rather than reset it all the way back to the beginning:
// revert to the first weapon
weaponControl.SetWeaponSlot(0);
The EnableCurrentWeapon() function on weaponControl will make sure that the
weapon is displayed correctly after it is re-enabled:
// show the current weapon (since it was hidden when the ship
// explosion was shown)
weaponControl.EnableCurrentWeapon();
}
Search WWH ::




Custom Search