Game Development Reference
In-Depth Information
//a message
Time.timeScale = 0;
//we also want the ship to stop
and prevent it
//shooting
ControlShip.canShoot=false;
ControlShip.shipSpeed=0;
//Display a "you won" message
DisplayGUI.GameEnd="YOU
DESTROYED THE ALIENS!";
//update the hiscore
if(DisplayScore.Score>DisplayScore.HiScore){
DisplayScore.HiScore=DisplayScore.Score;
}
}
}
7. To display a message for the player's ship being destroyed we put the same
command line into the
OnTriggerEnter()
function of the
ControlAli-
enBullet
script, with a different message. This is the updated
OnTrigger-
Enter()
function of the
ControlAlienBullet
script:
function OnTriggerEnter(other:Collider)
{
//check collision with player's ship
if(other.gameObject.tag=="PlayerShip")
{
Destroy(gameObject);
Destroy(other.gameObject);
//player's ship destroyed, pause
the game
Time.timeScale = 0;