示例#1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag.Equals("EnemySpaceship"))
        {
            // Run the kill method for enemy space ship
            collision.gameObject.GetComponent <EnemySpaceshipScript>().Kill();

            if (type != 2)
            {
                // Add to the score based on the enemy tag
                gs.AddToScore(collision.gameObject.GetComponent <Collider2D> ().tag);
            }
        }

        else if (collision.gameObject.tag.Contains("Enemy"))
        {
            // create an enemy object based on what was hit
            Enemy enemy = (Enemy)collision.gameObject.GetComponent("Enemy");

            // Based on type, accordingly deal damage to enemies
            if (type == 1 || type == 2)
            {
                // Run the Dead method for the enemy
                enemy.Dead(3);
            }
            else
            {
                enemy.Dead(1);
            }

            if (enemy.health == 0)
            {
                if (type != 2)
                {
                    // Add to the score based on the enemy tag
                    gs.AddToScore(collision.gameObject.GetComponent <Collider2D> ().tag);
                }
            }
        }

        else if (collision.gameObject.tag.Contains("Boss"))
        {
            BossScript boss = (BossScript)collision.gameObject.GetComponent("BossScript");
            boss.Dead(5);
            if (boss.health == 0)
            {
                sgs.complete = true;
            }
        }
    }