コード例 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.CompareTag("brick"))
        {
            Brick brickScript = collision.gameObject.GetComponent <Brick>(); //wejdz do skryptu Brick.cs i pobierz zmienna
            if (brickScript.hitsToBreak > 1)
            {
                brickScript.BreakBrick();
            }
            else
            {
                int randomChance = Random.Range(1, 101);
                if (randomChance > 95)
                {
                    Instantiate(powerUp, collision.transform.position, collision.transform.rotation);
                }

                Transform newExplosion = Instantiate(explosion, collision.transform.position, collision.transform.rotation); //Stworz wybuch w miejscu usuniecia bloku
                Destroy(newExplosion.gameObject, 2.5f);                                                                      //usun efekt wybuchu

                gm.updateScore(brickScript.points);                                                                          //ile punktow daje cegla

                gm.updateNumberOfBricks();                                                                                   //upadte liczbe cegiel

                Destroy(collision.gameObject);                                                                               //zniszcz blok(bricka)
            }
        }
    }
コード例 #2
0
ファイル: Ball.cs プロジェクト: Mowel/Break-Breaker
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("brick"))
        {
            Brick brick = other.gameObject.GetComponent <Brick>();
            if (brick.hitsToBreak > 1)
            {
                brick.BreakBrick();
            }
            else
            {
                int randChance = Random.Range(1, 101);
                if (randChance < 50)
                {
                    Instantiate(powerUp, other.transform.position, other.transform.rotation);
                }

                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
                Destroy(newExplosion.gameObject, 2.5f);

                gm.UpdateScore(brick.points);
                gm.UpdateNumberOfBricks();

                Destroy(other.gameObject);
            }
        }
    }
コード例 #3
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("brick"))
        {
            int randChance = Random.Range(1, 101);
            if (randChance < 20)
            {
                Instantiate(powerup, other.transform.position, other.transform.rotation);
            }

            Brick brickScript = other.gameObject.GetComponent <Brick>();
            if (brickScript.hitsToBreak > 1)
            {
                brickScript.BreakBrick();
            }
            else
            {
                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);

                Destroy(newExplosion.gameObject, 2.5f);
                gm.UpdateScore(brickScript.points);
                gm.UpdateNumberOfBricks();
                Destroy(other.gameObject);

                audioSources[1].Play();
            }
        }

        audioSources[0].Play();
    }