コード例 #1
0
    public int score;    //score of destroy the hazard
    //==========================================================================================================================
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "bolt")                                                                      // player when hit the rock by bolt
        {
            Destroy(gameObject);                                                                      //destroy the rock
            Destroy(other.gameObject);                                                                //destroy the bolt
            control.UpdateScore(score);                                                               // control this is calling from gamecontroller the updating the score when destroy rocks
            Instantiate(explosion, transform.position, transform.rotation);                           //make the animation of explosion appear in the sameplace of the player position
        }
        else if (other.tag == "Player" && (control.health - control.hazards.asteroidsDamage[0]) <= 0) //if the rock hit the player and can destroy him
        {
            Destroy(gameObject);
            Destroy(other.gameObject);
            Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
            control.decreaseHealth(score);

            control.loseWindow();
        }
        else if (other.tag == "Player")          //if the rock hit the player but can't destroy him
        {
            Destroy(gameObject);
            Instantiate(explosion, transform.position, transform.rotation);
            control.health = control.health - control.hazards.asteroidsDamage[0];
            control.decreaseHealth(score);
            control.UpdateScore(score);
            if (PowerUps.powerUpCounter > 0)
            {
                PowerUps.powerUpCounter--;
            }
        }
    }
コード例 #2
0
    //===========================================================================================================================================
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")                                                            // if player hit enemy
        {
            Destroy(gameObject);                                                              // destroy enemy
            Destroy(other.gameObject);                                                        // destroy player

            controller.enemies.enemiesDestroid++;                                             //increase the number of enemies that destroyed because we need to handle it with power up
            controller.UpdateScore(score);                                                    //  update new score
            Instantiate(playerExplosion, other.transform.position, other.transform.rotation); //explosion appear
            controller.decreaseHealth(100);
            controller.loseWindow();                                                          //player lose
        }
        else if (other.tag == "bolt")
        {                              // if bullet hit enemy
            Destroy(other.gameObject); //  destroy bullet
            numberOfHits++;            //increase the hits by bullet
            if (numberOfHits == MaxnumberOfHits)
            {
                Destroy(gameObject);
                controller.UpdateScore(score);                                  //update score
                controller.enemies.enemiesDestroid++;                           //increase the number of enemies that destroyed because we need to handle it with power up
                Instantiate(explosion, transform.position, transform.rotation); //explosion appear
            }
        }
    }
コード例 #3
0
    public GameObject playerExplosion;           //explosion
    //============================================================================================================================================================
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "boltEnemy")                                  // if bullet of enemy hit player
        {
            Destroy(other.gameObject);                                 //destroy enemy bullet
            controller.decreaseHealth(controller.enemies.enemyDamage); //decrease health of player

            if ((controller.health - controller.enemies.enemyDamage) <= 0)
            {
                Destroy(gameObject);                                                              //destroy enemy
                Instantiate(playerExplosion, other.transform.position, other.transform.rotation); //explosion appear
                controller.decreaseHealth(controller.enemies.enemyDamage);                        // decrease health bar
                controller.loseWindow();                                                          // lose screen appear
            }
            if (PowerUps.powerUpCounter > 0)
            {
                PowerUps.powerUpCounter--;
            }
        }
    }