예제 #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;
            }
        }
    }
예제 #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);
        }
    }
예제 #3
0
파일: CueForce.cs 프로젝트: ibrow19/GGJ19
    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);
        }
    }