Пример #1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Enemy" || other.tag == "powerUp")
        {
            return;
        }

        if (other.tag == "projectile")
        {
            Destroy(other.gameObject);
            gc.AddScore(scoreValue);
        }

        if (other.tag == "Player")
        {
            if (!gc.playerIsHit)
            {
                if (hb.GetPlayerHealth() == 0)
                {
                    GameObject exp_clone = (GameObject)Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
                    Destroy(other.gameObject);
                    Destroy(exp_clone, 0.5f);
                    gc.PlayerHit();
                    gc.GameOver();
                }
                else
                {
                    gc.PlayerHit();
                }
            }
            else
            {
                return;
            }
        }
        if (explosion != null)
        {
            GameObject exp_clone = (GameObject)Instantiate(explosion, transform.position, transform.rotation);
            Destroy(exp_clone, 0.5f);
        }
        Destroy(gameObject);
        op.Explosion();
        gc.hazardCount--;
        if (!pc.autoAttackActive && !pc.crossShotPickedUp)
        {
            gc.pUpCount++;
        }
        if (gc.pUpCount == 15)
        {
            Instantiate(powerUps [Random.Range(0, powerUps.Length - 1)], transform.position, transform.rotation);
            gc.pUpCount = 0;
        }
        if (smallerAsteroid.Length == 0)
        {
            return;             //The smallest asteroid will not spawn any new ones.
        }
        else
        {
            for (int i = 0; i < 2; i++)
            {
                Instantiate(smallerAsteroid[Random.Range(0, smallerAsteroid.Length - 1)], transform.position, transform.rotation);
                gc.hazardCount++;
            }
        }
    }