Exemplo n.º 1
0
    // if the enemy hits the death field
    void OnTriggerEnter2D()
    {
        ViscountessGame game = FindObjectOfType <ViscountessGame>();            // get game object

        game.currentNumberOfEnemies--;
        Destroy(gameObject);            // destroy enemy
    }
Exemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     rateOfFire       = 5;                                    // can fire this many times a second
     timeLastFired    = float.MinValue;                       // makes sure you can fire as soon as the game starts
     game             = FindObjectOfType <ViscountessGame>(); // find the game object
     source           = GetComponent <AudioSource>();         // get audio component for gameover
     gameOver         = false;
     numberOfMissiles = 0;
     rb = GetComponent <Rigidbody2D>();              // returns reference to rigidbody2d component
 }
Exemplo n.º 3
0
 void TakeDamage(int dmg)
 {
     health -= dmg;
     if (health <= 0)                                                 // if unit is killed
     {
         anim.SetBool("isDestroyed", true);                           // start explosion animation by setting transition constraint
         GetComponent <Collider2D>().enabled = false;                 // turn off collider so lasers will not be stopped
         explode = true;
         ViscountessGame game = FindObjectOfType <ViscountessGame>(); // get the main game object
         game.SendMessage("UpdateScore", pointsWorth);                // send point value to update score of the game
         game.currentNumberOfEnemies--;
         source.Play();                                               // play the destruction sound
         Destroy(gameObject, 1);                                      // destroy enemy after 1 second has elapsed
     }
 }