Ejemplo n.º 1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Ball")
        {
            // Play sounds.
            if (blocking)
            {
                audioSource.PlayOneShot(blockHitSound, 1);
            }
            else
            {
                audioSource.PlayOneShot(crabHitSound, 1);
            }

            RegularBall otherBall = collision.gameObject.GetComponent <RegularBall>();

            if (!blocking && otherBall.isPowered())
            {
                alive = false;
            }
        }
    }
Ejemplo n.º 2
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Ball")
        {
            // TODO: play audio here.

            RegularBall otherBall = collision.gameObject.GetComponent <RegularBall>();
            if (powered || otherBall.isPowered())
            {
                otherBall.powerUp();
                audioSource.PlayOneShot(fastBallHitSound, 1);
            }
            else
            {
                audioSource.PlayOneShot(slowBallHitSound, 1);
            }
        }
        else if (collision.gameObject.tag == "Table")
        {
            audioSource.PlayOneShot(tableHitSound, 1);
        }
    }
Ejemplo n.º 3
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        Vector3 dir = transform.rotation * new Vector3(1, 0, 0);

        // Correct direction based on parent scaling.
        if (refScale.x < 0)
        {
            dir *= -1;
        }

        // Apply force.
        collider.attachedRigidbody.AddForce(dir * force);

        if (collider.gameObject.tag == "Ball")
        {
            RegularBall ball = collider.gameObject.GetComponent <RegularBall>();
            ball.powerUp();
            audioSource.PlayOneShot(cueBallSound, 1);
        }
        else
        {
            audioSource.PlayOneShot(cueOtherSound, 1);
        }
    }