Game Development Reference
In-Depth Information
2. We need to add this line into two scripts. First in the
OnTriggerEnter()
function of the
ControlAlienBullet
script, which handles the event of
an enemy bullet hitting the player and second in the
Update()
function of
the
ControlSwarm
script, which handles the case of the entire swarm des-
troyed.
3. This is the updated
OnTriggerEnter()
function of the
ControlAli-
enBullet
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;
Debug.Log("Game Over");
//update the hiscore
if(DisplayScore.Score>DisplayScore.HiScore){
DisplayScore.HiScore=DisplayScore.Score;
}
}
//check collisions with barriers
if(other.gameObject.tag=="BarrierBrick"){
Destroy(gameObject);
Destroy(other.gameObject);
}
}