コード例 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        PlayerSave playerSave = FindObjectOfType <PlayerSave>();

        if (slingshotComboCount < 16)
        {
            slingshotComboCount++;
        }
        else
        {
            slingshotComboCount = 0;
            paddle.ActivateSlingshot();
        }

        Vector2 tweak = new Vector2(Random.Range(0f, 0.2f), Random.Range(0f, 0.2f));

        if (bHasStarted)
        {
            AudioSource audioSource = GetComponent <AudioSource>();
            if (collision.gameObject.tag == "Breakable")
            {
                AudioSource.PlayClipAtPoint(comboSFX[comboStage], Vector3.zero, sfxVolume);
                comboCountDown = comboLinkDuration;
                if (comboStage < maxComboStage)
                {
                    comboStage++;
                }
            }
            else if (collision.gameObject.tag == "Paddle")
            {
                AudioSource.PlayClipAtPoint(bounceSFX, Vector3.zero, sfxVolume);
                bSlingShotted = false;
                transform.Find("Slingshot").gameObject.SetActive(false);
            }
            else
            {
                AudioSource.PlayClipAtPoint(bounceSFX, Vector3.zero, sfxVolume);
                bSlingShotted = false;
                transform.Find("Slingshot").gameObject.SetActive(false);
                Instantiate(debris, transform.position, Quaternion.identity);
            }

            GetComponent <Rigidbody2D>().velocity += tweak;
        }
    }