void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Brick")) { rb.AddForce(Vector3.down * 100f); playSFX.PlayAudioSFX(0); BrickStats brickStats = collision.transform.GetComponent <BrickStats>(); if (brickStats != null) { gameManager.AddScore(brickStats.brickScoreValue); brickStats.DestroyBrick(); } Destroy(collision.gameObject, 0.1f); } if (collision.gameObject.CompareTag("Player")) { playSFX.PlayAudioSFX(1); PlayerMovement playerMovement = collision.gameObject.GetComponent <PlayerMovement>(); //print("Collide with Player!!"); if (playerMovement != null) { if (playerMovement.horizontalMovement >= 0.5f) { rb.AddForce(Vector3.right * 75f); if (rb.velocity.y < maxVelocity) { rb.AddForce(Vector3.up * 105f); } } else if (playerMovement.horizontalMovement <= -0.5f) { rb.AddForce(Vector3.right * -75f); if (rb.velocity.y < maxVelocity) { rb.AddForce(Vector3.up * 105f); } } else if (playerMovement.horizontalMovement == 0f) { if (rb.velocity.y < maxVelocity) { rb.AddForce(Vector3.up * 125f); } } } if (rb.useGravity) { rb.useGravity = false; } } if (collision.gameObject.CompareTag("Death")) { gameManager.SubtractLife(); resetBallInstructions.SetActive(true); isDead = true; ResetBall(); } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Brick")) { BrickStats brickStats = collision.transform.GetComponent <BrickStats>(); if (brickStats != null) { gameManager.AddScore(brickStats.brickScoreValue); brickStats.DestroyBrick(); playSFX.PlayAudioSFX(PlaySFX.Sound_HitBrick); } Destroy(collision.gameObject, 0.1f); } if (collision.gameObject.CompareTag("Death")) { gameManager.SubtractLife(); resetBallInstructions.SetActive(true); isDead = true; ResetBall(); } if (collision.gameObject.CompareTag("SideWall")) { rb.AddForce(Vector3.up * 100); } if (collision.gameObject.CompareTag("Player")) { PlayerMovement playerMovement = collision.gameObject.GetComponent <PlayerMovement>(); rb.AddForce(Vector3.up * 200); playSFX.PlayAudioSFX(PlaySFX.Sound_HitPaddle); if (playerMovement != null) { if (playerMovement.horizontalMovement >= 0.5f) { rb.AddForce(Vector3.right * 75f); if (rb.velocity.y < maxVelocity) { rb.AddForce(Vector3.up * 105f); } } else if (playerMovement.horizontalMovement <= -0.5f) { rb.AddForce(Vector3.right * -75f); if (rb.velocity.y < maxVelocity) { rb.AddForce(Vector3.up * 105f); } } else if (playerMovement.horizontalMovement == 0f) { if (rb.velocity.y < maxVelocity) { rb.AddForce(Vector3.up * 125f); } } } } }