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; } } }
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); } }
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); } }