Пример #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.CompareTag("Ball"))
        {
            if (levelLoader == null)
            {
                levelLoader = GetComponentInParent <LevelLoader>();
            }


            GameObject     go       = Instantiate(particles, transform.position, Quaternion.identity);
            ParticleSystem ps       = go.GetComponent <ParticleSystem>();
            var            settings = ps.main;
            Color          c        = GetComponent <SpriteRenderer>().color;
            settings.startColor = c;
            TextMeshPro text = go.GetComponentInChildren <TextMeshPro>();
            text.color = c;

            if (powerUp == ePowerUp.EXTRA_BALL)
            {
                levelLoader.ballManager.MakeBall(true, transform);
                powerUp = ePowerUp.NONE;
            }
            else if (powerUp == ePowerUp.SCORE_MULTIPLIER_TWO)
            {
                levelLoader.scoreMultiplier *= 2;
                go.GetComponentInChildren <FloatingText>().playMultiplierAudio = true;
            }
            else if (powerUp == ePowerUp.SCORE_MULTIPLIER_THREE)
            {
                levelLoader.scoreMultiplier *= 3;
                go.GetComponentInChildren <FloatingText>().playMultiplierAudio = true;
            }
            if (levelLoader != null)
            {
                text.text = "" + scoreValue * BallManager.ballsActive * levelLoader.scoreMultiplier;
                blocksDestroyed++;
                levelLoader.blocksLeft -= 1;
                levelLoader.AddScore(scoreValue);
            }

            if (spawnAnotherBlock)
            {
                LevelLoader loader = GetComponentInParent <LevelLoader>();
                blockSpawned.GetComponent <SpriteRenderer>().color = blockSpawnedColor;
                blockSpawned.transform.position = transform.position;
                blockSpawned.transform.rotation = transform.rotation;
                loader.CreateBlock(blockSpawned, transform.parent);
            }


            Destroy(this);
            Destroy(go, 1.0f);
            Destroy(gameObject, 0.01f);
        }
    }