Ejemplo n.º 1
0
    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.name == "StingerBullet(Clone)")
        {
            Destroy(col.gameObject);
        }
        else if (col.gameObject.name == "Bolt(Clone)")
        {
            Destroy(col.gameObject);
        }

        bool damagePlayer = false;

        StingerBullet enemy = col.gameObject.GetComponent <StingerBullet>(); // Enemy object, in this case an asteroid for testing purposes

        // If enemy exists
        if (enemy != null)
        {
            damagePlayer = true;
        }

        // Damage the player
        if (damagePlayer)
        {
            Health playerHealth = this.GetComponent <Health>();

            // Damage the player if their health is not 0
            if (playerHealth.hp != 0)
            {
                playerHealth.Damage(10, this.isEnemy); // Damage the player by x amount

                Debug.Log("Current Health: " + playerHealth.hp);
                setHealthandLiveText();

                /*
                 * if (playerHealth.hp <= 0)
                 * {
                 *  this.currentLives--; // decrement player live count
                 *  Debug.Log("Current Lives: " + this.currentLives);
                 *  setHealthandLiveText(); // update player lives
                 *
                 *  Run this if player live count is less than 0
                 *  if (this.currentLives <= 0)
                 *  {
                 *     Debug.Log("Game Over"); // Rip in pieces
                 *     Destroy(gameObject);
                 *  }
                 *  else
                 *  {
                 *      playerHealth.hp = maxHealth;
                 *      Debug.Log("Current Health: " + playerHealth.hp);
                 *      setHealthandLiveText(); // update health
                 *  }
                 * }
                 */
            }
        }
    }
Ejemplo n.º 2
0
    // This function displays the damage being dealt

    void OnCollisionEnter(Collision col)
    {
        bool damagePlayer = false;
        int  dam;

        if (col.gameObject.name == "StingerBullet(Clone)")
        {
            StingerBullet enemy = col.gameObject.GetComponent <StingerBullet>();
            if (enemy != null)
            {
                damagePlayer = true;
            }
            dam = 5;
        }
        else if (col.gameObject.name == "ChomperLazer(Clone)")
        {
            ChomperBullet enemy = col.gameObject.GetComponent <ChomperBullet>();
            if (enemy != null)
            {
                damagePlayer = true;
            }
            dam = 10;
        }
        else if (col.gameObject.name == "CrabberExplosion(Clone)")
        {
            CrabberExplosion enemy = col.gameObject.GetComponent <CrabberExplosion>();
            if (enemy != null)
            {
                damagePlayer = true;
            }
            dam = 10;
        }
        else if (col.gameObject.name == "StrikerProjectile(Clone)")
        {
            StrikerProjectile enemy = col.gameObject.GetComponent <StrikerProjectile>();
            if (enemy != null)
            {
                damagePlayer = true;
            }
            dam = 5;
        }
        else if (col.gameObject.name == "AsteroidUp(Clone)")
        {
            AsteroidUp enemy = col.gameObject.GetComponent <AsteroidUp>();
            if (enemy != null)
            {
                damagePlayer = true;
            }
            dam = 15;
        }
        else if (col.gameObject.name == "AsteroidDown(Clone)")
        {
            AsteroidDown enemy = col.gameObject.GetComponent <AsteroidDown>();
            if (enemy != null)
            {
                damagePlayer = true;
            }
            dam = 15;
        }
        else
        {
            dam = 0;
        }

        // Setting the Health and Life Text
        if (damagePlayer)
        {
            Health playerHealth = this.GetComponent <Health>();

            // Damage the player if their health is not 0
            if (playerHealth.hp > 0 && dam == 1 && Time.time > nextDam)
            {
                playerHealth.Damage(dam, this.isEnemy); // Damage the player by x amount

                Debug.Log("Current Health: " + playerHealth.hp);
                setHealthandLiveText();
                nextDam = Time.time + damRate;
            }
            else if (playerHealth.hp > 0 && dam == 5)
            {
                playerHealth.Damage(dam, this.isEnemy); // Damage the player by x amount

                Debug.Log("Current Health: " + playerHealth.hp);
                setHealthandLiveText();
            }
            else if (playerHealth.hp > 0 && dam == 10 && Time.time > nextDam)
            {
                playerHealth.Damage(dam, this.isEnemy); // Damage the player by x amount

                Debug.Log("Current Health: " + playerHealth.hp);
                setHealthandLiveText();
                nextDam = Time.time + damRate;
            }
            else if (playerHealth.hp > 0 && dam == 15 && Time.time > nextDam)
            {
                playerHealth.Damage(dam, this.isEnemy); // Damage the player by x amount

                Debug.Log("Current Health: " + playerHealth.hp);
                setHealthandLiveText();
                nextDam = Time.time + damRate;
            }
        }
        if (col.gameObject.name == "StingerBullet(Clone)")
        {
            Destroy(col.gameObject);
        }
        else if (col.gameObject.name == "Bolt(Clone)")
        {
            Destroy(col.gameObject);
        }
        else if (col.gameObject.name == "StrikerProjectile(Clone)")
        {
            Destroy(col.gameObject);
        }
    }